3v4l.org

run code in 300+ PHP versions simultaneously
<?php $phpbb_code = '<!-- BEGIN navlinks --> <span>{navlinks.U_VIEW_FORUM}{$MICRODATA}{navlinks.MICRODATA}{navlinks.FORUM_NAME}</span> <!-- END navlinks -->'; function fix_begin_tokens($code, $parent_nodes = array()) { // PHP 5.3 cannot use $this in an anonymous function, so use this as a work-around $parent_class = $this; $callback = function ($matches) use ($parent_class, $parent_nodes) { $hard_parents = explode('.', $matches[1]); array_pop($hard_parents); // ends with . if ($hard_parents) { $parent_nodes = array_merge($hard_parents, $parent_nodes); } $name = $matches[2]; $subset = trim(substr($matches[3], 1, -1)); // Remove parenthesis $body = $matches[4]; // Replace <!-- BEGINELSE --> $body = str_replace('<!-- BEGINELSE -->', '{% else %}', $body); // Is the designer wanting to call another loop in a loop? // <!-- BEGIN loop --> // <!-- BEGIN !loop2 --> // <!-- END !loop2 --> // <!-- END loop --> // 'loop2' is actually on the same nesting level as 'loop' you assign // variables to it with template->assign_block_vars('loop2', array(...)) if (strpos($name, '!') === 0) { // Count the number if ! occurrences $count = substr_count($name, '!'); for ($i = 0; $i < $count; $i++) { array_pop($parent_nodes); $name = substr($name, 1); } } // Remove all parent nodes, e.g. foo, bar from foo.bar.foobar.VAR foreach ($parent_nodes as $node) { $body = preg_replace('#([^a-zA-Z0-9_])' . $node . '\.([a-zA-Z0-9_]+)\.#', '$1$2.', $body); } // Add current node to list of parent nodes for child nodes $parent_nodes[] = $name; // Recursive...fix any child nodes $body = $parent_class->fix_begin_tokens($body, $parent_nodes); // Need the parent variable name array_pop($parent_nodes); $parent = (!empty($parent_nodes)) ? end($parent_nodes) . '.' : ''; if ($subset !== '') { $subset = '|subset(' . $subset . ')'; } $parent = ($parent) ?: 'loops.'; // Turn into a Twig for loop return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; }; return preg_replace_callback('#<!-- BEGIN ((?:[a-zA-Z0-9_]+\.)*)([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1\2 -->#s', $callback, $code); } $code = $this->fix_begin_tokens($phpbb_code, ''); echo $code;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HC9W8
function name:  (null)
number of ops:  9
compiled vars:  !0 = $phpbb_code, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%21--+BEGIN+navlinks+--%3E%0A%09%09%09%3Cspan%3E%7Bnavlinks.U_VIEW_FORUM%7D%7B%24MICRODATA%7D%7Bnavlinks.MICRODATA%7D%7Bnavlinks.FORUM_NAME%7D%3C%2Fspan%3E%0A%09%09%09%3C%21--+END+navlinks+--%3E'
   64     1        FETCH_THIS                                       $3      
          2        INIT_METHOD_CALL                                         $3, 'fix_begin_tokens'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAL_EX                                              ''
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   66     7        ECHO                                                     !1
          8      > RETURN                                                   1

Function fix_begin_tokens:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HC9W8
function name:  fix_begin_tokens
number of ops:  15
compiled vars:  !0 = $code, !1 = $parent_nodes, !2 = $parent_class, !3 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   10     2        FETCH_THIS                                       ~4      
          3        ASSIGN                                                   !2, ~4
   11     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHC9W8%3A11%240'
          5        BIND_LEXICAL                                             ~6, !2
          6        BIND_LEXICAL                                             ~6, !1
          7        ASSIGN                                                   !3, ~6
   61     8        INIT_FCALL                                               'preg_replace_callback'
          9        SEND_VAL                                                 '%23%3C%21--+BEGIN+%28%28%3F%3A%5Ba-zA-Z0-9_%5D%2B%5C.%29%2A%29%28%5B%21a-zA-Z0-9_%5D%2B%29%28%5C%28%5B0-9%2C%5C-%5D%2B%5C%29%29%3F+--%3E%28.%2B%3F%29%3C%21--+END+%5C1%5C2+--%3E%23s'
         10        SEND_VAR                                                 !3
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $8      
         13      > RETURN                                                   $8
   62    14*     > RETURN                                                   null

End of function fix_begin_tokens

Function %00%7Bclosure%7D%2Fin%2FHC9W8%3A11%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 62
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 51
Branch analysis from position: 62
2 jumps found. (Code = 77) Position 1 = 63, Position 2 = 73
Branch analysis from position: 63
2 jumps found. (Code = 78) Position 1 = 64, Position 2 = 73
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 93
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 100
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
Branch analysis from position: 93
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 100
Branch analysis from position: 97
Branch analysis from position: 100
Branch analysis from position: 73
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 51
Branch analysis from position: 62
Branch analysis from position: 51
Branch analysis from position: 62
Branch analysis from position: 18
filename:       /in/HC9W8
function name:  {closure}
number of ops:  114
compiled vars:  !0 = $matches, !1 = $parent_class, !2 = $parent_nodes, !3 = $hard_parents, !4 = $name, !5 = $subset, !6 = $body, !7 = $count, !8 = $i, !9 = $node, !10 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   13     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '.'
          5        FETCH_DIM_R                                      ~11     !0, 1
          6        SEND_VAL                                                 ~11
          7        DO_ICALL                                         $12     
          8        ASSIGN                                                   !3, $12
   14     9        INIT_FCALL                                               'array_pop'
         10        SEND_REF                                                 !3
         11        DO_ICALL                                                 
   15    12      > JMPZ                                                     !3, ->18
   17    13    >   INIT_FCALL                                               'array_merge'
         14        SEND_VAR                                                 !3
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $15     
         17        ASSIGN                                                   !2, $15
   19    18    >   FETCH_DIM_R                                      ~17     !0, 2
         19        ASSIGN                                                   !4, ~17
   20    20        INIT_FCALL                                               'trim'
         21        INIT_FCALL                                               'substr'
         22        FETCH_DIM_R                                      ~19     !0, 3
         23        SEND_VAL                                                 ~19
         24        SEND_VAL                                                 1
         25        SEND_VAL                                                 -1
         26        DO_ICALL                                         $20     
         27        SEND_VAR                                                 $20
         28        DO_ICALL                                         $21     
         29        ASSIGN                                                   !5, $21
   21    30        FETCH_DIM_R                                      ~23     !0, 4
         31        ASSIGN                                                   !6, ~23
   23    32        INIT_FCALL                                               'str_replace'
         33        SEND_VAL                                                 '%3C%21--+BEGINELSE+--%3E'
         34        SEND_VAL                                                 '%7B%25+else+%25%7D'
         35        SEND_VAR                                                 !6
         36        DO_ICALL                                         $25     
         37        ASSIGN                                                   !6, $25
   31    38        INIT_FCALL                                               'strpos'
         39        SEND_VAR                                                 !4
         40        SEND_VAL                                                 '%21'
         41        DO_ICALL                                         $27     
         42        IS_IDENTICAL                                             $27, 0
         43      > JMPZ                                                     ~28, ->62
   34    44    >   INIT_FCALL                                               'substr_count'
         45        SEND_VAR                                                 !4
         46        SEND_VAL                                                 '%21'
         47        DO_ICALL                                         $29     
         48        ASSIGN                                                   !7, $29
   35    49        ASSIGN                                                   !8, 0
         50      > JMP                                                      ->60
   37    51    >   INIT_FCALL                                               'array_pop'
         52        SEND_REF                                                 !2
         53        DO_ICALL                                                 
   38    54        INIT_FCALL                                               'substr'
         55        SEND_VAR                                                 !4
         56        SEND_VAL                                                 1
         57        DO_ICALL                                         $33     
         58        ASSIGN                                                   !4, $33
   35    59        PRE_INC                                                  !8
         60    >   IS_SMALLER                                               !8, !7
         61      > JMPNZ                                                    ~36, ->51
   42    62    > > FE_RESET_R                                       $37     !2, ->73
         63    > > FE_FETCH_R                                               $37, !9, ->73
   44    64    >   INIT_FCALL                                               'preg_replace'
         65        CONCAT                                           ~38     '%23%28%5B%5Ea-zA-Z0-9_%5D%29', !9
         66        CONCAT                                           ~39     ~38, '%5C.%28%5Ba-zA-Z0-9_%5D%2B%29%5C.%23'
         67        SEND_VAL                                                 ~39
         68        SEND_VAL                                                 '%241%242.'
         69        SEND_VAR                                                 !6
         70        DO_ICALL                                         $40     
         71        ASSIGN                                                   !6, $40
   42    72      > JMP                                                      ->63
         73    >   FE_FREE                                                  $37
   47    74        ASSIGN_DIM                                               !2
         75        OP_DATA                                                  !4
   49    76        INIT_METHOD_CALL                                         !1, 'fix_begin_tokens'
         77        SEND_VAR_EX                                              !6
         78        SEND_VAR_EX                                              !2
         79        DO_FCALL                                      0  $43     
         80        ASSIGN                                                   !6, $43
   51    81        INIT_FCALL                                               'array_pop'
         82        SEND_REF                                                 !2
         83        DO_ICALL                                                 
   52    84        ISSET_ISEMPTY_CV                                 ~46     !2
         85        BOOL_NOT                                         ~47     ~46
         86      > JMPZ                                                     ~47, ->93
         87    >   INIT_FCALL                                               'end'
         88        SEND_REF                                                 !2
         89        DO_ICALL                                         $48     
         90        CONCAT                                           ~49     $48, '.'
         91        QM_ASSIGN                                        ~50     ~49
         92      > JMP                                                      ->94
         93    >   QM_ASSIGN                                        ~50     ''
         94    >   ASSIGN                                                   !10, ~50
   53    95        IS_NOT_IDENTICAL                                         !5, ''
         96      > JMPZ                                                     ~52, ->100
   55    97    >   CONCAT                                           ~53     '%7Csubset%28', !5
         98        CONCAT                                           ~54     ~53, '%29'
         99        ASSIGN                                                   !5, ~54
   57   100    >   JMP_SET                                          ~56     !10, ->102
        101        QM_ASSIGN                                        ~56     'loops.'
        102        ASSIGN                                                   !10, ~56
   59   103        ROPE_INIT                                     9  ~59     '%7B%25+for+'
        104        ROPE_ADD                                      1  ~59     ~59, !4
        105        ROPE_ADD                                      2  ~59     ~59, '+in+'
        106        ROPE_ADD                                      3  ~59     ~59, !10
        107        ROPE_ADD                                      4  ~59     ~59, !4
        108        ROPE_ADD                                      5  ~59     ~59, !5
        109        ROPE_ADD                                      6  ~59     ~59, '+%25%7D'
        110        ROPE_ADD                                      7  ~59     ~59, !6
        111        ROPE_END                                      8  ~58     ~59, '%7B%25+endfor+%25%7D'
        112      > RETURN                                                   ~58
   60   113*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHC9W8%3A11%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.62 ms | 1408 KiB | 35 Q