3v4l.org

run code in 300+ PHP versions simultaneously
<?php $codes = <<<'CODES' [column] [row] [column][/column] [column][/column] [/row] [/column] CODES; $html = str_replace(['[', ']'], ['<', '>'], $codes); libxml_use_internal_errors(true); $dom = new \DOMDocument(); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach($dom->getElementsByTagName('row') as $row) { foreach($row->getElementsByTagName('column') as $column) { $column->appendChild($dom->createTextNode('test')); $column->setAttribute('class', 'test'); } } $tags = getTags($dom->documentElement); echo var_export($tags, true); function getTags($element, $tags = []) { $tag = ['tagName' => $element->tagName]; if ($element->hasAttributes()) { foreach ($element->attributes as $attribute) { $tag['attributes'][$attribute->name] = $attribute->value; } } if ('' !== ($nodeValue = trim($element->textContent)) && false === $element->hasChildNodes()) { $tag['nodeValue'] = $nodeValue; } if ($element->hasChildNodes()) { foreach ($element->childNodes as $childElement) { if ($childElement->nodeType !== XML_ELEMENT_NODE) { continue; } $tag[] = getTags($childElement, $tags); } } $tags[] = $tag; return $tags; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 40
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 40
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 38
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 38
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/h1eMR
function name:  (null)
number of ops:  53
compiled vars:  !0 = $codes, !1 = $html, !2 = $dom, !3 = $row, !4 = $column, !5 = $tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5Bcolumn%5D%0A++++%5Brow%5D%0A++++++++%5Bcolumn%5D%5B%2Fcolumn%5D%0A++++++++%5Bcolumn%5D%5B%2Fcolumn%5D%0A++++%5B%2Frow%5D%0A%5B%2Fcolumn%5D'
   11     1        INIT_FCALL                                               'str_replace'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 <array>
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !1, $7
   12     7        INIT_FCALL                                               'libxml_use_internal_errors'
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                                 
   13    10        NEW                                              $10     'DOMDocument'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $10
   14    13        INIT_METHOD_CALL                                         !2, 'loadHTML'
         14        SEND_VAR_EX                                              !1
         15        SEND_VAL_EX                                              8196
         16        DO_FCALL                                      0          
   16    17        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
         18        SEND_VAL_EX                                              'row'
         19        DO_FCALL                                      0  $14     
         20      > FE_RESET_R                                       $15     $14, ->40
         21    > > FE_FETCH_R                                               $15, !3, ->40
   17    22    >   INIT_METHOD_CALL                                         !3, 'getElementsByTagName'
         23        SEND_VAL_EX                                              'column'
         24        DO_FCALL                                      0  $16     
         25      > FE_RESET_R                                       $17     $16, ->38
         26    > > FE_FETCH_R                                               $17, !4, ->38
   18    27    >   INIT_METHOD_CALL                                         !4, 'appendChild'
         28        INIT_METHOD_CALL                                         !2, 'createTextNode'
         29        SEND_VAL_EX                                              'test'
         30        DO_FCALL                                      0  $18     
         31        SEND_VAR_NO_REF_EX                                       $18
         32        DO_FCALL                                      0          
   19    33        INIT_METHOD_CALL                                         !4, 'setAttribute'
         34        SEND_VAL_EX                                              'class'
         35        SEND_VAL_EX                                              'test'
         36        DO_FCALL                                      0          
   17    37      > JMP                                                      ->26
         38    >   FE_FREE                                                  $17
   16    39      > JMP                                                      ->21
         40    >   FE_FREE                                                  $15
   23    41        INIT_FCALL_BY_NAME                                       'getTags'
         42        CHECK_FUNC_ARG                                           
         43        FETCH_OBJ_FUNC_ARG                               $21     !2, 'documentElement'
         44        SEND_FUNC_ARG                                            $21
         45        DO_FCALL                                      0  $22     
         46        ASSIGN                                                   !5, $22
   24    47        INIT_FCALL                                               'var_export'
         48        SEND_VAR                                                 !5
         49        SEND_VAL                                                 <true>
         50        DO_ICALL                                         $24     
         51        ECHO                                                     $24
   51    52      > RETURN                                                   1

Function gettags:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 50
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 37, Position 2 = 49
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 49
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 42
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
Branch analysis from position: 50
Branch analysis from position: 32
Branch analysis from position: 29
Branch analysis from position: 17
Branch analysis from position: 18
filename:       /in/h1eMR
function name:  getTags
number of ops:  54
compiled vars:  !0 = $element, !1 = $tags, !2 = $tag, !3 = $attribute, !4 = $nodeValue, !5 = $childElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   28     2        FETCH_OBJ_R                                      ~6      !0, 'tagName'
          3        INIT_ARRAY                                       ~7      ~6, 'tagName'
          4        ASSIGN                                                   !2, ~7
   30     5        INIT_METHOD_CALL                                         !0, 'hasAttributes'
          6        DO_FCALL                                      0  $9      
          7      > JMPZ                                                     $9, ->18
   31     8    >   FETCH_OBJ_R                                      ~10     !0, 'attributes'
          9      > FE_RESET_R                                       $11     ~10, ->17
         10    > > FE_FETCH_R                                               $11, !3, ->17
   32    11    >   FETCH_OBJ_R                                      ~13     !3, 'name'
         12        FETCH_OBJ_R                                      ~15     !3, 'value'
         13        FETCH_DIM_W                                      $12     !2, 'attributes'
         14        ASSIGN_DIM                                               $12, ~13
         15        OP_DATA                                                  ~15
   31    16      > JMP                                                      ->10
         17    >   FE_FREE                                                  $11
   36    18    >   INIT_FCALL                                               'trim'
         19        FETCH_OBJ_R                                      ~16     !0, 'textContent'
         20        SEND_VAL                                                 ~16
         21        DO_ICALL                                         $17     
         22        ASSIGN                                           ~18     !4, $17
         23        IS_NOT_IDENTICAL                                 ~19     ~18, ''
         24      > JMPZ_EX                                          ~19     ~19, ->29
         25    >   INIT_METHOD_CALL                                         !0, 'hasChildNodes'
         26        DO_FCALL                                      0  $20     
         27        TYPE_CHECK                                    4  ~21     $20
         28        BOOL                                             ~19     ~21
         29    > > JMPZ                                                     ~19, ->32
   37    30    >   ASSIGN_DIM                                               !2, 'nodeValue'
         31        OP_DATA                                                  !4
   40    32    >   INIT_METHOD_CALL                                         !0, 'hasChildNodes'
         33        DO_FCALL                                      0  $23     
         34      > JMPZ                                                     $23, ->50
   41    35    >   FETCH_OBJ_R                                      ~24     !0, 'childNodes'
         36      > FE_RESET_R                                       $25     ~24, ->49
         37    > > FE_FETCH_R                                               $25, !5, ->49
   42    38    >   FETCH_OBJ_R                                      ~26     !5, 'nodeType'
         39        IS_NOT_IDENTICAL                                         ~26, 1
         40      > JMPZ                                                     ~27, ->42
   43    41    > > JMP                                                      ->37
   45    42    >   INIT_FCALL_BY_NAME                                       'getTags'
         43        SEND_VAR_EX                                              !5
         44        SEND_VAR_EX                                              !1
         45        DO_FCALL                                      0  $29     
         46        ASSIGN_DIM                                               !2
         47        OP_DATA                                                  $29
   41    48      > JMP                                                      ->37
         49    >   FE_FREE                                                  $25
   48    50    >   ASSIGN_DIM                                               !1
         51        OP_DATA                                                  !2
   50    52      > RETURN                                                   !1
   51    53*     > RETURN                                                   null

End of function gettags

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.77 ms | 1010 KiB | 17 Q