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).)*'|(#|//).*|(/\*)(?:[^*/]|\*(?!/)|(?<!\*)/)*\*/|(<!--)(?:[^->]|-(?!->)|(?<!--)>)*-->)~ 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 class=\"{$class}\" data-marker=\"{$encoded}\">{$m[0]}</span>"; }, $string);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Y9XE
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%3F%3A%5B%5E%2A%2F%5D%7C%5C%2A%28%3F%21%2F%29%7C%28%3F%3C%21%5C%2A%29%2F%29%2A%5C%2A%2F%7C%28%3C%21--%29%28%3F%3A%5B%5E-%3E%5D%7C-%28%3F%21-%3E%29%7C%28%3F%3C%21--%29%3E%29%2A--%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                          ~3      [0]
   48     7        SEND_VAL                                                 ~3
          8        SEND_VAR                                                 !0
   43     9        DO_ICALL                                         $4      
   48    10        ECHO                                                     $4
         11      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Y9XE
function name:  {closure}
number of ops:  25
compiled vars:  !0 = $m, !1 = $marker, !2 = $encoded, !3 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        FETCH_DIM_R                                      ~4      !0, 1
          2        ASSIGN                                                   !1, ~4
   45     3        INIT_FCALL                                               'addcslashes'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 '%22'
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !2, $6
   46     8        FETCH_CONSTANT                                   ~8      'LOOKUP'
          9        FETCH_DIM_IS                                     ~9      ~8, !1
         10        COALESCE                                         ~10     ~9
         11        NOP                                                      
         12        FAST_CONCAT                                      ~11     'missing+', !2
         13        QM_ASSIGN                                        ~10     ~11
         14        ASSIGN                                                   !3, ~10
   47    15        ROPE_INIT                                     7  ~15     '%3Cspan+class%3D%22'
         16        ROPE_ADD                                      1  ~15     ~15, !3
         17        ROPE_ADD                                      2  ~15     ~15, '%22+data-marker%3D%22'
         18        ROPE_ADD                                      3  ~15     ~15, !2
         19        ROPE_ADD                                      4  ~15     ~15, '%22%3E'
         20        FETCH_DIM_R                                      ~13     !0, 0
         21        ROPE_ADD                                      5  ~15     ~15, ~13
         22        ROPE_END                                      6  ~14     ~15, '%3C%2Fspan%3E'
         23      > RETURN                                                   ~14
   48    24*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.65 ms | 1006 KiB | 15 Q