3v4l.org

run code in 300+ PHP versions simultaneously
<?php // old and new strings $old = "Foo \r\nFoo\r\nBar\r\nQux"; $new = "Foo\nBar\nBaz"; // convert all line endings to the same type $old = str_replace(["\r\n", "\r"], "\n", $old); $new = str_replace(["\r\n", "\r"], "\n", $new); // seperate into lines $old_lines = explode("\n", $old); $new_lines = explode("\n", $new); // optional: remove whitespace so spaces don't trigger falsely array_walk($old_lines, function(&$value) { $value = rtrim($value); }); array_walk($new_lines, function(&$value) { $value = rtrim($value); }); // figure out which one is longer if (count($old_lines) >= count($new_lines)) { $primary = $old_lines; $secondary = $new_lines; } else { $primary = $new_lines; $secondary = $old_lines; } // compare line by line $results = []; foreach ($primary as $key => $value) { if (key_exists($key, $secondary)) { if ($primary[$key] == $secondary[$key]) { $results[] = "MATCH"; } else { $results[] = "DIFFERENT"; } } else { $results[] = "MISSING"; } } var_dump($old_lines); var_dump($new_lines); var_dump($results);
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { [0]=> string(3) "Foo" [1]=> string(3) "Foo" [2]=> string(3) "Bar" [3]=> string(3) "Qux" } array(3) { [0]=> string(3) "Foo" [1]=> string(3) "Bar" [2]=> string(3) "Baz" } array(4) { [0]=> string(5) "MATCH" [1]=> string(9) "DIFFERENT" [2]=> string(9) "DIFFERENT" [3]=> string(7) "MISSING" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
57.61 ms | 402 KiB | 8 Q