3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = <<<'STRING' //single line comment random text ... #another comment Multiline comments: /* this is a multiline comment with 'squote and "dquote" matches the whole thing */ // single line 'squoted' "dquoted" comment w/ extra " for no reason More comments <!-- yatta yatta yatta yatta --> Quotes: "also matches strings with \" escaped quotes or 'the other kind of quotation marks in it' " a "nested 'squote with nested \"dquote\"'" assuming only outermost quoting matters for formatting 'matches the end quote because it it not escaped \\' STRING; const PATTERN = <<<'PATTERN' ~(?|(")(?:[^"\\]|\\(?s).)*"|(')(?:[^'\\]|\\(?s).)*'|(#|//).*|(/\*)(?s).*?\*/|(<!--)(?s).*?-->)~ PATTERN; const LOOKUP = [ '#' => 'gainsboro', '//' => 'lightgrey', '/*' => 'silver', '<!--' => 'darkgrey', "'" => 'mint', '"' => 'aqua' ]; echo preg_replace_callback(PATTERN, function($m) { //$marker = $m[1]; //$encoded = addcslashes($marker, '"'); //$class = LOOKUP[$marker] ?? "missing $encoded"; return "<span style=\"color:" . LOOKUP[$m[1]] . "\">{$m[0]}</span>"; }, $string);
Output for git.master, git.master_jit, rfc.property-hooks
<span style="color:lightgrey">//single line comment</span> random text ... <span style="color:gainsboro">#another comment</span> Multiline comments: <span style="color:silver">/* this is a multiline comment with 'squote and "dquote" matches the whole thing */</span> <span style="color:lightgrey">// single line 'squoted' "dquoted" comment w/ extra " for no reason</span> More comments <span style="color:darkgrey"><!-- yatta yatta yatta yatta --></span> Quotes: <span style="color:aqua">"also matches strings with \" escaped quotes or 'the other kind of quotation marks in it' "</span> a <span style="color:aqua">"nested 'squote with nested \"dquote\"'"</span> assuming only outermost quoting matters for formatting <span style="color:mint">'matches the end quote because it it not escaped \\'</span>

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:
44.55 ms | 403 KiB | 8 Q