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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vVjuO
function name:  (null)
number of ops:  12
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%2F%2Fsingle+line+comment%0A%0Arandom+text+...+%23another+comment%0A%0AMultiline+comments%3A%0A%0A%2F%2A+this+is+a+multiline+comment%0A%0Awith+%27squote+and+%22dquote%22%0A%0Amatches+the+whole+thing+%2A%2F%0A%0A%2F%2F+single+line+%27squoted%27+%22dquoted%22+comment+w%2F+extra+%22+for+no+reason%0A%0AMore+comments+%3C%21--+yatta+yatta%0Ayatta%0Ayatta+--%3E%0A%0AQuotes%3A%0A%0A%22also+matches+strings+with+%5C%22+escaped+quotes+or+%27the+other+kind+of+quotation+marks+in+it%27+%22%0A%0Aa+%22nested+%27squote+with+nested+%5C%22dquote%5C%22%27%22+assuming+only+outermost+quoting+matters+for+formatting%0A%0A%27matches+the+end+quote+because+it+it+not+escaped+%5C%5C%27'
   30     1        DECLARE_CONST                                            'PATTERN', '%7E%28%3F%7C%28%22%29%28%3F%3A%5B%5E%22%5C%5C%5D%7C%5C%5C%28%3Fs%29.%29%2A%22%7C%28%27%29%28%3F%3A%5B%5E%27%5C%5C%5D%7C%5C%5C%28%3Fs%29.%29%2A%27%7C%28%23%7C%2F%2F%29.%2A%7C%28%2F%5C%2A%29%28%3Fs%29.%2A%3F%5C%2A%2F%7C%28%3C%21--%29%28%3Fs%29.%2A%3F--%3E%29%7E'
   34     2        DECLARE_CONST                                            'LOOKUP', <array>
   43     3        INIT_FCALL                                               'preg_replace_callback'
          4        FETCH_CONSTANT                                   ~2      'PATTERN'
          5        SEND_VAL                                                 ~2
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FvVjuO%3A43%240'
   48     7        SEND_VAL                                                 ~3
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $4      
         10        ECHO                                                     $4
         11      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FvVjuO%3A43%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vVjuO
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   47     1        FETCH_CONSTANT                                   ~1      'LOOKUP'
          2        FETCH_DIM_R                                      ~2      !0, 1
          3        FETCH_DIM_R                                      ~3      ~1, ~2
          4        CONCAT                                           ~4      '%3Cspan+style%3D%22color%3A', ~3
          5        ROPE_INIT                                     3  ~7      '%22%3E'
          6        FETCH_DIM_R                                      ~5      !0, 0
          7        ROPE_ADD                                      1  ~7      ~7, ~5
          8        ROPE_END                                      2  ~6      ~7, '%3C%2Fspan%3E'
          9        CONCAT                                           ~9      ~4, ~6
         10      > RETURN                                                   ~9
   48    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FvVjuO%3A43%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.76 ms | 1396 KiB | 15 Q