3v4l.org

run code in 500+ 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 = 18, Position 2 = 37
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 37
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 35
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 35
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/h1eMR
function name:  (null)
number of ops:  50
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        FRAMELESS_ICALL_3                str_replace         ~7      <array>, <array>
          2        OP_DATA                                                      !0
          3        ASSIGN                                                       !1, ~7
   12     4        INIT_FCALL                                                   'libxml_use_internal_errors'
          5        SEND_VAL                                                     <true>
          6        DO_ICALL                                                     
   13     7        NEW                                                  $10     'DOMDocument'
          8        DO_FCALL                                          0          
          9        ASSIGN                                                       !2, $10
   14    10        INIT_METHOD_CALL                                             !2, 'loadHTML'
         11        SEND_VAR_EX                                                  !1
         12        SEND_VAL_EX                                                  8196
         13        DO_FCALL                                          0          
   16    14        INIT_METHOD_CALL                                             !2, 'getElementsByTagName'
         15        SEND_VAL_EX                                                  'row'
         16        DO_FCALL                                          0  $14     
         17      > FE_RESET_R                                           $15     $14, ->37
         18    > > FE_FETCH_R                                                   $15, !3, ->37
   17    19    >   INIT_METHOD_CALL                                             !3, 'getElementsByTagName'
         20        SEND_VAL_EX                                                  'column'
         21        DO_FCALL                                          0  $16     
         22      > FE_RESET_R                                           $17     $16, ->35
         23    > > FE_FETCH_R                                                   $17, !4, ->35
   18    24    >   INIT_METHOD_CALL                                             !4, 'appendChild'
         25        INIT_METHOD_CALL                                             !2, 'createTextNode'
         26        SEND_VAL_EX                                                  'test'
         27        DO_FCALL                                          0  $18     
         28        SEND_VAR_NO_REF_EX                                           $18
         29        DO_FCALL                                          0          
   19    30        INIT_METHOD_CALL                                             !4, 'setAttribute'
         31        SEND_VAL_EX                                                  'class'
         32        SEND_VAL_EX                                                  'test'
         33        DO_FCALL                                          0          
   17    34      > JMP                                                          ->23
         35    >   FE_FREE                                                      $17
   16    36      > JMP                                                          ->18
         37    >   FE_FREE                                                      $15
   23    38        INIT_FCALL_BY_NAME                                           'getTags'
         39        CHECK_FUNC_ARG                                               
         40        FETCH_OBJ_FUNC_ARG                                   $21     !2, 'documentElement'
         41        SEND_FUNC_ARG                                                $21
         42        DO_FCALL                                          0  $22     
         43        ASSIGN                                                       !5, $22
   24    44        INIT_FCALL                                                   'var_export'
         45        SEND_VAR                                                     !5
         46        SEND_VAL                                                     <true>
         47        DO_ICALL                                             $24     
         48        ECHO                                                         $24
   51    49      > 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 = 23, Position 2 = 27
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 48
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 47
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 47
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 48
Branch analysis from position: 30
Branch analysis from position: 27
Branch analysis from position: 17
Branch analysis from position: 18
filename:       /in/h1eMR
function name:  getTags
number of ops:  52
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    >   FETCH_OBJ_R                                          ~16     !0, 'textContent'
         19        FRAMELESS_ICALL_1                trim                ~17     ~16
         20        ASSIGN                                               ~18     !4, ~17
         21        IS_NOT_IDENTICAL                                     ~19     ~18, ''
         22      > JMPZ_EX                                              ~19     ~19, ->27
         23    >   INIT_METHOD_CALL                                             !0, 'hasChildNodes'
         24        DO_FCALL                                          0  $20     
         25        TYPE_CHECK                                        4  ~21     $20
         26        BOOL                                                 ~19     ~21
         27    > > JMPZ                                                         ~19, ->30
   37    28    >   ASSIGN_DIM                                                   !2, 'nodeValue'
         29        OP_DATA                                                      !4
   40    30    >   INIT_METHOD_CALL                                             !0, 'hasChildNodes'
         31        DO_FCALL                                          0  $23     
         32      > JMPZ                                                         $23, ->48
   41    33    >   FETCH_OBJ_R                                          ~24     !0, 'childNodes'
         34      > FE_RESET_R                                           $25     ~24, ->47
         35    > > FE_FETCH_R                                                   $25, !5, ->47
   42    36    >   FETCH_OBJ_R                                          ~26     !5, 'nodeType'
         37        IS_NOT_IDENTICAL                                             ~26, 1
         38      > JMPZ                                                         ~27, ->40
   43    39    > > JMP                                                          ->35
   45    40    >   INIT_FCALL_BY_NAME                                           'getTags'
         41        SEND_VAR_EX                                                  !5
         42        SEND_VAR_EX                                                  !1
         43        DO_FCALL                                          0  $29     
         44        ASSIGN_DIM                                                   !2
         45        OP_DATA                                                      $29
   41    46      > JMP                                                          ->35
         47    >   FE_FREE                                                      $25
   48    48    >   ASSIGN_DIM                                                   !1
         49        OP_DATA                                                      !2
   50    50      > RETURN                                                       !1
   51    51*     > RETURN                                                       null

End of function gettags

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
196.77 ms | 1666 KiB | 15 Q