3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = ' <table id="myTable"> <tbody> <tr> <td>08/20/18</td> <td> <a href="https://example.com/1a">Text 1 A</a> </td> <td> <a href="https://example.com/1b">Test 1 B</a> </td> </tr> <tr> <td>08/21/18</td> <td> <a href="https://example.com/2a">Text 2 A</a> </td> <td> <a href="https://example.com/2b">Test 2 B</a> </td> </tr> </tbody> </table> '; $data = []; $doc = new DOMDocument(); $doc->loadHTML('<?xml encoding="utf-8" ?>' . $html); $xpath = new DOMXPath($doc); $trs = $xpath->query("//*[@id='myTable']/tbody/tr"); foreach ($trs as $i => $tr) { /** @var DOMElement $td */ foreach ($tr->childNodes as $td) { if ($td instanceof DOMElement) { $row = []; /** @var DOMElement $a */ foreach ($td->childNodes as $a) { /** @var DOMAttr $attribute */ foreach ($a->attributes as $attribute) { $row[$attribute->name] = $attribute->value; } $row['content'] = $td->nodeValue; } $data[$i][] = $row; } } } print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 49
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 49
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 47
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 47
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 46
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 42
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 42
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 37
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 42
Branch analysis from position: 46
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 47
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
filename:       /in/6cZfR
function name:  (null)
number of ops:  54
compiled vars:  !0 = $html, !1 = $data, !2 = $doc, !3 = $xpath, !4 = $trs, !5 = $tr, !6 = $i, !7 = $td, !8 = $row, !9 = $a, !10 = $attribute
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0A%3Ctable+id%3D%22myTable%22%3E%0A++++%3Ctbody%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd%3E08%2F20%2F18%3C%2Ftd%3E%0A++++++++++++%3Ctd%3E+%3Ca+href%3D%22https%3A%2F%2Fexample.com%2F1a%22%3EText+1+A%3C%2Fa%3E+%3C%2Ftd%3E%0A++++++++++++%3Ctd%3E+%3Ca+href%3D%22https%3A%2F%2Fexample.com%2F1b%22%3ETest+1+B%3C%2Fa%3E+%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd%3E08%2F21%2F18%3C%2Ftd%3E%0A++++++++++++%3Ctd%3E+%3Ca+href%3D%22https%3A%2F%2Fexample.com%2F2a%22%3EText+2+A%3C%2Fa%3E+%3C%2Ftd%3E%0A++++++++++++%3Ctd%3E+%3Ca+href%3D%22https%3A%2F%2Fexample.com%2F2b%22%3ETest+2+B%3C%2Fa%3E+%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++%3C%2Ftbody%3E%0A%3C%2Ftable%3E%0A'
   20     1        ASSIGN                                                   !1, <array>
   22     2        NEW                                              $13     'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $13
   23     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        CONCAT                                           ~16     '%3C%3Fxml+encoding%3D%22utf-8%22+%3F%3E', !0
          7        SEND_VAL_EX                                              ~16
          8        DO_FCALL                                      0          
   24     9        NEW                                              $18     'DOMXPath'
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $18
   25    13        INIT_METHOD_CALL                                         !3, 'query'
         14        SEND_VAL_EX                                              '%2F%2F%2A%5B%40id%3D%27myTable%27%5D%2Ftbody%2Ftr'
         15        DO_FCALL                                      0  $21     
         16        ASSIGN                                                   !4, $21
   26    17      > FE_RESET_R                                       $23     !4, ->49
         18    > > FE_FETCH_R                                       ~24     $23, !5, ->49
         19    >   ASSIGN                                                   !6, ~24
   28    20        FETCH_OBJ_R                                      ~26     !5, 'childNodes'
         21      > FE_RESET_R                                       $27     ~26, ->47
         22    > > FE_FETCH_R                                               $27, !7, ->47
   29    23    >   INSTANCEOF                                               !7, 'DOMElement'
         24      > JMPZ                                                     ~28, ->46
   30    25    >   ASSIGN                                                   !8, <array>
   32    26        FETCH_OBJ_R                                      ~30     !7, 'childNodes'
         27      > FE_RESET_R                                       $31     ~30, ->42
         28    > > FE_FETCH_R                                               $31, !9, ->42
   34    29    >   FETCH_OBJ_R                                      ~32     !9, 'attributes'
         30      > FE_RESET_R                                       $33     ~32, ->37
         31    > > FE_FETCH_R                                               $33, !10, ->37
   35    32    >   FETCH_OBJ_R                                      ~34     !10, 'name'
         33        FETCH_OBJ_R                                      ~36     !10, 'value'
         34        ASSIGN_DIM                                               !8, ~34
         35        OP_DATA                                                  ~36
   34    36      > JMP                                                      ->31
         37    >   FE_FREE                                                  $33
   37    38        FETCH_OBJ_R                                      ~38     !7, 'nodeValue'
         39        ASSIGN_DIM                                               !8, 'content'
         40        OP_DATA                                                  ~38
   32    41      > JMP                                                      ->28
         42    >   FE_FREE                                                  $31
   39    43        FETCH_DIM_W                                      $39     !1, !6
         44        ASSIGN_DIM                                               $39
         45        OP_DATA                                                  !8
   28    46    > > JMP                                                      ->22
         47    >   FE_FREE                                                  $27
   26    48      > JMP                                                      ->18
         49    >   FE_FREE                                                  $23
   44    50        INIT_FCALL                                               'print_r'
         51        SEND_VAR                                                 !1
         52        DO_ICALL                                                 
         53      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.67 ms | 1089 KiB | 14 Q