3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<html> <body> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR> <TD BGCOLOR=000000> <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4> <TR STYLE="font-weight: 700;" ALIGN=CENTER BGCOLOR=99CCFF> <td>Product</td> <td>Quantity</td> <td>Retail Price</td> <td>Total Retail Price</td> <td>UPC</td> </tr> <tr bgcolor="FFFFFF"> <td style="">Smith High-Water Chroma Pop+ Polar Chromic NXT Sunglasses, Black</td> <td style="text-align: right;">1</td> <td style="text-align: right;">$259.00</td> <td style="text-align: right;">$259.00</td> <td style=""></td> </tr> <tr bgcolor="FFFFFF"> <td style="">Guest 2613A Charge Pro Series Marine Battery Charger (12/24-Volt, 15-Amps 5/5/5, Triple Output)</td> <td style="text-align: right;">1</td> <td style="text-align: right;">$179.18</td> <td style="text-align: right;">$179.18</td> <td style=""></td> </tr> </table> </body> </html>'; $dom = new DOMDocument(); $dom->loadHTML($html); // Grab first table from dom and store its rows and columns by tag name. $rows = $dom->getElementsByTagName('table')->item(1)->getElementsByTagName('tr'); $headers = $rows->item(0)->getElementsByTagName('td'); $resultArray = []; $keys = []; foreach($headers as $header) { $keys[] = strtolower($header->nodeValue); } print_r($keys); foreach($rows as $row) { $item = []; foreach($keys as $i=>$key) { $cells = $row->getElementsByTagName('td'); $item[$key] = $cells->item($i)->nodeValue; } $resultArray[] = $item; } print_r($resultArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 60
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 60
Branch analysis from position: 41
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 56
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 56
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 56
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 35
filename:       /in/guRje
function name:  (null)
number of ops:  65
compiled vars:  !0 = $html, !1 = $dom, !2 = $rows, !3 = $headers, !4 = $resultArray, !5 = $keys, !6 = $header, !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+BORDER%3D0+CELLSPACING%3D0+CELLPADDING%3D0%3E+%3CTR%3E+%3CTD+BGCOLOR%3D000000%3E+%3CTABLE+BORDER%3D0+CELLSPACING%3D1+CELLPADDING%3D4%3E+%3CTR+STYLE%3D%22font-weight%3A+700%3B%22+ALIGN%3DCENTER+BGCOLOR%3D99CCFF%3E%0A++++++++%3Ctd%3EProduct%3C%2Ftd%3E%0A%09%3Ctd%3EQuantity%3C%2Ftd%3E%0A%09%3Ctd%3ERetail+Price%3C%2Ftd%3E%0A%09%3Ctd%3ETotal+Retail+Price%3C%2Ftd%3E%0A++++++++%3Ctd%3EUPC%3C%2Ftd%3E%0A%3C%2Ftr%3E%0A%0A%3Ctr+bgcolor%3D%22FFFFFF%22%3E%0A++++++++++++++++%3Ctd+style%3D%22%22%3ESmith+High-Water+Chroma+Pop%2B+Polar+Chromic+NXT+Sunglasses%2C+Black%3C%2Ftd%3E%0A%09%09%3Ctd+style%3D%22text-align%3A+right%3B%22%3E1%3C%2Ftd%3E%0A%09%09%3Ctd+style%3D%22text-align%3A+right%3B%22%3E%24259.00%3C%2Ftd%3E%0A%09%09%3Ctd+style%3D%22text-align%3A+right%3B%22%3E%24259.00%3C%2Ftd%3E%0A++++++++++++++++%3Ctd+style%3D%22%22%3E%3C%2Ftd%3E%0A%3C%2Ftr%3E%0A%0A%3Ctr+bgcolor%3D%22FFFFFF%22%3E%0A++++++++++++++++%3Ctd+style%3D%22%22%3EGuest+2613A+Charge+Pro+Series+Marine+Battery+Charger+%2812%2F24-Volt%2C+15-Amps+5%2F5%2F5%2C+Triple+Output%29%3C%2Ftd%3E%0A%09%09%3Ctd+style%3D%22text-align%3A+right%3B%22%3E1%3C%2Ftd%3E%0A%09%09%3Ctd+style%3D%22text-align%3A+right%3B%22%3E%24179.18%3C%2Ftd%3E%0A%09%09%3Ctd+style%3D%22text-align%3A+right%3B%22%3E%24179.18%3C%2Ftd%3E%0A++++++++++++++++%3Ctd+style%3D%22%22%3E%3C%2Ftd%3E%0A%3C%2Ftr%3E%0A%3C%2Ftable%3E%0A%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   33     1        NEW                                              $13     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $13
   34     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   37     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'table'
          9        DO_FCALL                                      0  $17     
         10        INIT_METHOD_CALL                                         $17, 'item'
         11        SEND_VAL_EX                                              1
         12        DO_FCALL                                      0  $18     
         13        INIT_METHOD_CALL                                         $18, 'getElementsByTagName'
         14        SEND_VAL_EX                                              'tr'
         15        DO_FCALL                                      0  $19     
         16        ASSIGN                                                   !2, $19
   38    17        INIT_METHOD_CALL                                         !2, 'item'
         18        SEND_VAL_EX                                              0
         19        DO_FCALL                                      0  $21     
         20        INIT_METHOD_CALL                                         $21, 'getElementsByTagName'
         21        SEND_VAL_EX                                              'td'
         22        DO_FCALL                                      0  $22     
         23        ASSIGN                                                   !3, $22
   40    24        ASSIGN                                                   !4, <array>
   41    25        ASSIGN                                                   !5, <array>
   43    26      > FE_RESET_R                                       $26     !3, ->35
         27    > > FE_FETCH_R                                               $26, !6, ->35
   44    28    >   INIT_FCALL                                               'strtolower'
         29        FETCH_OBJ_R                                      ~28     !6, 'nodeValue'
         30        SEND_VAL                                                 ~28
         31        DO_ICALL                                         $29     
         32        ASSIGN_DIM                                               !5
         33        OP_DATA                                                  $29
   43    34      > JMP                                                      ->27
         35    >   FE_FREE                                                  $26
   46    36        INIT_FCALL                                               'print_r'
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                                 
   48    39      > FE_RESET_R                                       $31     !2, ->60
         40    > > FE_FETCH_R                                               $31, !7, ->60
   49    41    >   ASSIGN                                                   !8, <array>
   50    42      > FE_RESET_R                                       $33     !5, ->56
         43    > > FE_FETCH_R                                       ~34     $33, !9, ->56
         44    >   ASSIGN                                                   !10, ~34
   51    45        INIT_METHOD_CALL                                         !7, 'getElementsByTagName'
         46        SEND_VAL_EX                                              'td'
         47        DO_FCALL                                      0  $36     
         48        ASSIGN                                                   !11, $36
   52    49        INIT_METHOD_CALL                                         !11, 'item'
         50        SEND_VAR_EX                                              !10
         51        DO_FCALL                                      0  $39     
         52        FETCH_OBJ_R                                      ~40     $39, 'nodeValue'
         53        ASSIGN_DIM                                               !8, !9
         54        OP_DATA                                                  ~40
   50    55      > JMP                                                      ->43
         56    >   FE_FREE                                                  $33
   54    57        ASSIGN_DIM                                               !4
         58        OP_DATA                                                  !8
   48    59      > JMP                                                      ->40
         60    >   FE_FREE                                                  $31
   57    61        INIT_FCALL                                               'print_r'
         62        SEND_VAR                                                 !4
         63        DO_ICALL                                                 
         64      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.91 ms | 1404 KiB | 17 Q