3v4l.org

run code in 300+ PHP versions simultaneously
<?php // test function: function parse($html) { // I have split the pattern in two lines not to have long lines alerts by the PHP.net form: $pattern = "/<([\w]+)([^>]*?)(([\s]*\/>)|". "(>((([^<]*?|<\!\-\-.*?\-\->)|(?R))*)<\/\\1[\s]*>))/sm"; preg_match_all($pattern, $html, $matches, PREG_OFFSET_CAPTURE); $elements = array(); foreach ($matches[0] as $key => $match) { $elements[] = (object)array( 'node' => $match[0], 'offset' => $match[1], 'tagname' => $matches[1][$key][0], 'attributes' => isset($matches[2][$key][0]) ? $matches[2][$key][0] : '', 'omittag' => ($matches[4][$key][1] > -1), // boolean 'inner_html' => isset($matches[6][$key][0]) ? $matches[6][$key][0] : '' ); } return $elements; } // random html nodes as example: $html = <<<EOD <div id="airport"> <div geo:position="1.234324,3.455546" class="index"> <!-- comment test: <div class="index_top" /> --> <div class="element decorator"> <ul class="lister"> <li onclick="javascript:item.showAttribute('desc');"> <h3 class="outline"> <a href="http://php.net/manual/en/regexp.reference.recursive.php" onclick="openPopup()">Link</a> </h3> <div class="description">Sample description</div> </li> </ul> </div> <div class="clean-line"></div> </div> </div> <div id="omittag_test" rel="rootChild" /> EOD; // application: $elements = parse($html); if (count($elements) > 0) { echo "Elements found: <b>".count($elements)."</b><br />"; foreach ($elements as $element) { echo "<p>Tpl node: <pre>".htmlentities($element->node)."</pre> Tagname: <tt>".$element->tagname."</tt><br /> Attributes: <tt>".$element->attributes."</tt><br /> Omittag: <tt>".($element->omittag ? 'true' : 'false')."</tt><br /> Inner HTML: <pre>".htmlentities($element->inner_html)."</pre></p>"; } } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 42
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 41
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 41
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 42
filename:       /in/g6kgK
function name:  (null)
number of ops:  43
compiled vars:  !0 = $html, !1 = $elements, !2 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, '%3Cdiv+id%3D%22airport%22%3E%0A++++%3Cdiv+geo%3Aposition%3D%221.234324%2C3.455546%22+class%3D%22index%22%3E%0A++++++++%3C%21--+comment+test%3A%0A++++++++%3Cdiv+class%3D%22index_top%22+%2F%3E%0A++++++++--%3E%0A++++++++%3Cdiv+class%3D%22element+decorator%22%3E%0A++++++++++++++++%3Cul+class%3D%22lister%22%3E%0A++++++++++++++++++++%3Cli+onclick%3D%22javascript%3Aitem.showAttribute%28%27desc%27%29%3B%22%3E%0A++++++++++++++++++++++++%3Ch3+class%3D%22outline%22%3E%0A++++++++++++++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fphp.net%2Fmanual%2Fen%2Fregexp.reference.recursive.php%22+onclick%3D%22openPopup%28%29%22%3ELink%3C%2Fa%3E%0A++++++++++++++++++++++++%3C%2Fh3%3E%0A++++++++++++++++++++++++%3Cdiv+class%3D%22description%22%3ESample+description%3C%2Fdiv%3E%0A++++++++++++++++++++%3C%2Fli%3E%0A++++++++++++++++%3C%2Ful%3E%0A++++++++%3C%2Fdiv%3E%0A++++++++%3Cdiv+class%3D%22clean-line%22%3E%3C%2Fdiv%3E%0A++++%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%3Cdiv+id%3D%22omittag_test%22+rel%3D%22rootChild%22+%2F%3E'
   47     1        INIT_FCALL                                               'parse'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   49     5        COUNT                                            ~6      !1
          6        IS_SMALLER                                               0, ~6
          7      > JMPZ                                                     ~7, ->42
   50     8    >   COUNT                                            ~8      !1
          9        CONCAT                                           ~9      'Elements+found%3A+%3Cb%3E', ~8
         10        CONCAT                                           ~10     ~9, '%3C%2Fb%3E%3Cbr+%2F%3E'
         11        ECHO                                                     ~10
   52    12      > FE_RESET_R                                       $11     !1, ->41
         13    > > FE_FETCH_R                                               $11, !2, ->41
   53    14    >   INIT_FCALL                                               'htmlentities'
         15        FETCH_OBJ_R                                      ~12     !2, 'node'
         16        SEND_VAL                                                 ~12
         17        DO_ICALL                                         $13     
         18        CONCAT                                           ~14     '%3Cp%3ETpl+node%3A+%3Cpre%3E', $13
         19        CONCAT                                           ~15     ~14, '%3C%2Fpre%3E%0A++++++++Tagname%3A+%3Ctt%3E'
   54    20        FETCH_OBJ_R                                      ~16     !2, 'tagname'
         21        CONCAT                                           ~17     ~15, ~16
         22        CONCAT                                           ~18     ~17, '%3C%2Ftt%3E%3Cbr+%2F%3E%0A++++++++Attributes%3A+%3Ctt%3E'
   55    23        FETCH_OBJ_R                                      ~19     !2, 'attributes'
         24        CONCAT                                           ~20     ~18, ~19
         25        CONCAT                                           ~21     ~20, '%3C%2Ftt%3E%3Cbr+%2F%3E%0A++++++++Omittag%3A+%3Ctt%3E'
   56    26        FETCH_OBJ_R                                      ~22     !2, 'omittag'
         27      > JMPZ                                                     ~22, ->30
         28    >   QM_ASSIGN                                        ~23     'true'
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~23     'false'
         31    >   CONCAT                                           ~24     ~21, ~23
         32        CONCAT                                           ~25     ~24, '%3C%2Ftt%3E%3Cbr+%2F%3E%0A++++++++Inner+HTML%3A+%3Cpre%3E'
   57    33        INIT_FCALL                                               'htmlentities'
         34        FETCH_OBJ_R                                      ~26     !2, 'inner_html'
         35        SEND_VAL                                                 ~26
         36        DO_ICALL                                         $27     
         37        CONCAT                                           ~28     ~25, $27
         38        CONCAT                                           ~29     ~28, '%3C%2Fpre%3E%3C%2Fp%3E'
         39        ECHO                                                     ~29
   52    40      > JMP                                                      ->13
         41    >   FE_FREE                                                  $11
   60    42    > > RETURN                                                   1

Function parse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 52
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 52
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
Branch analysis from position: 46
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/g6kgK
function name:  parse
number of ops:  55
compiled vars:  !0 = $html, !1 = $pattern, !2 = $matches, !3 = $elements, !4 = $match, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, '%2F%3C%28%5B%5Cw%5D%2B%29%28%5B%5E%3E%5D%2A%3F%29%28%28%5B%5Cs%5D%2A%5C%2F%3E%29%7C%28%3E%28%28%28%5B%5E%3C%5D%2A%3F%7C%3C%5C%21%5C-%5C-.%2A%3F%5C-%5C-%3E%29%7C%28%3FR%29%29%2A%29%3C%5C%2F%5C1%5B%5Cs%5D%2A%3E%29%29%2Fsm'
    7     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        SEND_VAL                                                 256
          7        DO_ICALL                                                 
    8     8        ASSIGN                                                   !3, <array>
   10     9        FETCH_DIM_R                                      ~9      !2, 0
         10      > FE_RESET_R                                       $10     ~9, ->52
         11    > > FE_FETCH_R                                       ~11     $10, !4, ->52
         12    >   ASSIGN                                                   !5, ~11
   12    13        FETCH_DIM_R                                      ~14     !4, 0
         14        INIT_ARRAY                                       ~15     ~14, 'node'
   13    15        FETCH_DIM_R                                      ~16     !4, 1
         16        ADD_ARRAY_ELEMENT                                ~15     ~16, 'offset'
   14    17        FETCH_DIM_R                                      ~17     !2, 1
         18        FETCH_DIM_R                                      ~18     ~17, !5
         19        FETCH_DIM_R                                      ~19     ~18, 0
         20        ADD_ARRAY_ELEMENT                                ~15     ~19, 'tagname'
   15    21        FETCH_DIM_IS                                     ~20     !2, 2
         22        FETCH_DIM_IS                                     ~21     ~20, !5
         23        ISSET_ISEMPTY_DIM_OBJ                         0          ~21, 0
         24      > JMPZ                                                     ~22, ->30
         25    >   FETCH_DIM_R                                      ~23     !2, 2
         26        FETCH_DIM_R                                      ~24     ~23, !5
         27        FETCH_DIM_R                                      ~25     ~24, 0
         28        QM_ASSIGN                                        ~26     ~25
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~26     ''
         31    >   ADD_ARRAY_ELEMENT                                ~15     ~26, 'attributes'
   16    32        FETCH_DIM_R                                      ~27     !2, 4
         33        FETCH_DIM_R                                      ~28     ~27, !5
         34        FETCH_DIM_R                                      ~29     ~28, 1
   12    35        IS_SMALLER                                       ~30     -1, ~29
         36        ADD_ARRAY_ELEMENT                                ~15     ~30, 'omittag'
   17    37        FETCH_DIM_IS                                     ~31     !2, 6
         38        FETCH_DIM_IS                                     ~32     ~31, !5
         39        ISSET_ISEMPTY_DIM_OBJ                         0          ~32, 0
         40      > JMPZ                                                     ~33, ->46
         41    >   FETCH_DIM_R                                      ~34     !2, 6
         42        FETCH_DIM_R                                      ~35     ~34, !5
         43        FETCH_DIM_R                                      ~36     ~35, 0
         44        QM_ASSIGN                                        ~37     ~36
         45      > JMP                                                      ->47
         46    >   QM_ASSIGN                                        ~37     ''
         47    >   ADD_ARRAY_ELEMENT                                ~15     ~37, 'inner_html'
         48        CAST                                          8  ~38     ~15
   11    49        ASSIGN_DIM                                               !3
   17    50        OP_DATA                                                  ~38
   10    51      > JMP                                                      ->11
         52    >   FE_FREE                                                  $10
   20    53      > RETURN                                                   !3
   21    54*     > RETURN                                                   null

End of function parse

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.08 ms | 1407 KiB | 18 Q