3v4l.org

run code in 300+ PHP versions simultaneously
<?php $depth = 0; $traverse = [0, 0, 0]; $tags = ['table', 'row', 'cell']; $regex = []; foreach ($tags as $key=>$tag) $regex[$key] = '/(\['.$tag.'((?:[\s\.\#]+[a-z]*)*)\]+[^\[]((?:.|\s)*?(?=(?:\['.$tag.')|$)))/'; echo var_export($tags),PHP_EOL; echo var_export($regex),PHP_EOL; $content = "[table] [row] [cell] [cell] [row] [cell] [cell] [table] [row] [row] [cell] [row] "; $f_parse = function($matches) use (&$depth, &$traverse, $tags, $regex, &$f_parse) { $traverse[++$depth]++; if ($depth < count($regex)) { preg_replace_callback( $regex[$depth], $f_parse, $matches[0] ); } /* echo "$depth | ${traverse[$depth]} | $tags, ${regex[$depth]}", PHP_EOL; $result = ""; if ($depth < count($regex)) { preg_replace_callback( $regex[$depth], $f_parse, $matches[0] ); } return $result;*/ echo $depth, ' | ', $traverse[$depth], ' | ', PHP_EOL; $traverse[$depth--]--; return $depth; }; $content = preg_replace_callback( $regex[$depth], $f_parse, $content ); echo $content, "\n"; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/KnMrE
function name:  (null)
number of ops:  43
compiled vars:  !0 = $depth, !1 = $traverse, !2 = $tags, !3 = $regex, !4 = $tag, !5 = $key, !6 = $content, !7 = $f_parse
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 0
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, <array>
    7     4      > FE_RESET_R                                       $12     !2, ->14
          5    > > FE_FETCH_R                                       ~13     $12, !4, ->14
          6    >   ASSIGN                                                   !5, ~13
    8     7        CONCAT                                           ~16     '%2F%28%5C%5B', !4
          8        CONCAT                                           ~17     ~16, '%28%28%3F%3A%5B%5Cs%5C.%5C%23%5D%2B%5Ba-z%5D%2A%29%2A%29%5C%5D%2B%5B%5E%5C%5B%5D%28%28%3F%3A.%7C%5Cs%29%2A%3F%28%3F%3D%28%3F%3A%5C%5B'
          9        CONCAT                                           ~18     ~17, !4
         10        CONCAT                                           ~19     ~18, '%29%7C%24%29%29%29%2F'
         11        ASSIGN_DIM                                               !3, !5
         12        OP_DATA                                                  ~19
    7    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $12
   10    15        INIT_FCALL                                               'var_export'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $20     
         18        ECHO                                                     $20
         19        ECHO                                                     '%0A'
   11    20        INIT_FCALL                                               'var_export'
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $21     
         23        ECHO                                                     $21
         24        ECHO                                                     '%0A'
   13    25        ASSIGN                                                   !6, '%5Btable%5D%0A++++%5Brow%5D%0A++++++++%5Bcell%5D%0A++++++++%5Bcell%5D%0A++++%5Brow%5D%0A++++++++%5Bcell%5D%0A++++++++%5Bcell%5D%0A%5Btable%5D%0A++++%5Brow%5D%0A++++%5Brow%5D%0A++++++++%5Bcell%5D%0A++++%5Brow%5D%0A'
   26    26        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FKnMrE%3A26%240'
         27        BIND_LEXICAL                                             ~23, !0
         28        BIND_LEXICAL                                             ~23, !1
         29        BIND_LEXICAL                                             ~23, !2
         30        BIND_LEXICAL                                             ~23, !3
         31        BIND_LEXICAL                                             ~23, !7
         32        ASSIGN                                                   !7, ~23
   53    33        INIT_FCALL                                               'preg_replace_callback'
   54    34        FETCH_DIM_R                                      ~25     !3, !0
         35        SEND_VAL                                                 ~25
   55    36        SEND_VAR                                                 !7
   56    37        SEND_VAR                                                 !6
         38        DO_ICALL                                         $26     
   53    39        ASSIGN                                                   !6, $26
   58    40        ECHO                                                     !6
         41        ECHO                                                     '%0A'
   71    42      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FKnMrE%3A26%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/KnMrE
function name:  {closure}
number of ops:  30
compiled vars:  !0 = $matches, !1 = $depth, !2 = $traverse, !3 = $tags, !4 = $regex, !5 = $f_parse
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
          4        BIND_STATIC                                              !4
          5        BIND_STATIC                                              !5
   27     6        PRE_INC                                          ~6      !1
          7        FETCH_DIM_RW                                     $7      !2, ~6
          8        PRE_INC                                                  $7
   28     9        COUNT                                            ~9      !4
         10        IS_SMALLER                                               !1, ~9
         11      > JMPZ                                                     ~10, ->19
   30    12    >   INIT_FCALL                                               'preg_replace_callback'
   31    13        FETCH_DIM_R                                      ~11     !4, !1
         14        SEND_VAL                                                 ~11
   32    15        SEND_VAR                                                 !5
   33    16        FETCH_DIM_R                                      ~12     !0, 0
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                                 
   48    19    >   ECHO                                                     !1
         20        ECHO                                                     '+%7C+'
         21        FETCH_DIM_R                                      ~14     !2, !1
         22        ECHO                                                     ~14
         23        ECHO                                                     '+%7C+'
         24        ECHO                                                     '%0A'
   49    25        POST_DEC                                         ~15     !1
         26        FETCH_DIM_RW                                     $16     !2, ~15
         27        PRE_DEC                                                  $16
   50    28      > RETURN                                                   !1
   51    29*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FKnMrE%3A26%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.68 ms | 1400 KiB | 17 Q