3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<html> <body> <table> <thead> <tr> <th>Name</th> <th>Date</th> </tr> </thead> <tbody> <tr> <td>Chad</td> <td>10/23/1996</td> </tr> <tr> <td>Rebecca</td> <td>05/03/2001</td> </tbody> </table> </body> </html>'; $dom = new DOMDocument(); $dom->loadHTML($html); $headers = $dom->getElementsByTagName('th'); foreach($headers as $header) { $keys[] = strtolower($header->nodeValue); } $rows = $dom->getElementsByTagName('tbody')->item(0)->getElementsByTagName('tr'); $result = []; foreach($rows as $row) { $item = []; foreach($keys as $i => $key) { $cells = $row->getElementsByTagName('td'); $item[$key] = $cells->item($i)->nodeValue; } $result[] = $item; } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 53
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 53
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 49
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 49
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 49
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 20
filename:       /in/JO0hE
function name:  (null)
number of ops:  58
compiled vars:  !0 = $html, !1 = $dom, !2 = $headers, !3 = $header, !4 = $keys, !5 = $rows, !6 = $result, !7 = $row, !8 = $item, !9 = $key, !10 = $i, !11 = $cells
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A%3Cbody%3E%0A++++%3Ctable%3E%0A++++++++%3Cthead%3E%0A++++++++++++%3Ctr%3E%0A++++++++++++++++%3Cth%3EName%3C%2Fth%3E%0A++++++++++++++++%3Cth%3EDate%3C%2Fth%3E%0A++++++++++++%3C%2Ftr%3E%0A++++++++%3C%2Fthead%3E%0A++++++++%3Ctbody%3E%0A++++++++++++%3Ctr%3E%0A++++++++++++++++%3Ctd%3EChad%3C%2Ftd%3E%0A++++++++++++++++%3Ctd%3E10%2F23%2F1996%3C%2Ftd%3E%0A++++++++++++%3C%2Ftr%3E%0A++++++++++++%3Ctr%3E%0A++++++++++++++++%3Ctd%3ERebecca%3C%2Ftd%3E%0A++++++++++++++++%3Ctd%3E05%2F03%2F2001%3C%2Ftd%3E%0A++++++++%3C%2Ftbody%3E%0A++++%3C%2Ftable%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   25     1        NEW                                              $13     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $13
   26     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'th'
          9        DO_FCALL                                      0  $17     
         10        ASSIGN                                                   !2, $17
   30    11      > FE_RESET_R                                       $19     !2, ->20
         12    > > FE_FETCH_R                                               $19, !3, ->20
   31    13    >   INIT_FCALL                                               'strtolower'
         14        FETCH_OBJ_R                                      ~21     !3, 'nodeValue'
         15        SEND_VAL                                                 ~21
         16        DO_ICALL                                         $22     
         17        ASSIGN_DIM                                               !4
         18        OP_DATA                                                  $22
   30    19      > JMP                                                      ->12
         20    >   FE_FREE                                                  $19
   34    21        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         22        SEND_VAL_EX                                              'tbody'
         23        DO_FCALL                                      0  $23     
         24        INIT_METHOD_CALL                                         $23, 'item'
         25        SEND_VAL_EX                                              0
         26        DO_FCALL                                      0  $24     
         27        INIT_METHOD_CALL                                         $24, 'getElementsByTagName'
         28        SEND_VAL_EX                                              'tr'
         29        DO_FCALL                                      0  $25     
         30        ASSIGN                                                   !5, $25
   35    31        ASSIGN                                                   !6, <array>
   37    32      > FE_RESET_R                                       $28     !5, ->53
         33    > > FE_FETCH_R                                               $28, !7, ->53
   38    34    >   ASSIGN                                                   !8, <array>
   39    35      > FE_RESET_R                                       $30     !4, ->49
         36    > > FE_FETCH_R                                       ~31     $30, !9, ->49
         37    >   ASSIGN                                                   !10, ~31
   40    38        INIT_METHOD_CALL                                         !7, 'getElementsByTagName'
         39        SEND_VAL_EX                                              'td'
         40        DO_FCALL                                      0  $33     
         41        ASSIGN                                                   !11, $33
   41    42        INIT_METHOD_CALL                                         !11, 'item'
         43        SEND_VAR_EX                                              !10
         44        DO_FCALL                                      0  $36     
         45        FETCH_OBJ_R                                      ~37     $36, 'nodeValue'
         46        ASSIGN_DIM                                               !8, !9
         47        OP_DATA                                                  ~37
   39    48      > JMP                                                      ->36
         49    >   FE_FREE                                                  $30
   43    50        ASSIGN_DIM                                               !6
         51        OP_DATA                                                  !8
   37    52      > JMP                                                      ->33
         53    >   FE_FREE                                                  $28
   46    54        INIT_FCALL                                               'var_dump'
         55        SEND_VAR                                                 !6
         56        DO_ICALL                                                 
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.82 ms | 1400 KiB | 17 Q