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); } foreach($rows as $i => $row) { if ($i<1) {continue;} $item = []; foreach($keys as $j=>$key) { $cells = $row->getElementsByTagName('td'); $item[$key] = $cells->item($j)->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 = 37, Position 2 = 61
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 61
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
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 57
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 57
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 57
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
Branch analysis from position: 35
filename:       /in/OeTA2
function name:  (null)
number of ops:  66
compiled vars:  !0 = $html, !1 = $dom, !2 = $rows, !3 = $headers, !4 = $resultArray, !5 = $keys, !6 = $header, !7 = $row, !8 = $i, !9 = $item, !10 = $key, !11 = $j, !12 = $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                                              $14     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $14
   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  $18     
         10        INIT_METHOD_CALL                                         $18, 'item'
         11        SEND_VAL_EX                                              1
         12        DO_FCALL                                      0  $19     
         13        INIT_METHOD_CALL                                         $19, 'getElementsByTagName'
         14        SEND_VAL_EX                                              'tr'
         15        DO_FCALL                                      0  $20     
         16        ASSIGN                                                   !2, $20
   38    17        INIT_METHOD_CALL                                         !2, 'item'
         18        SEND_VAL_EX                                              0
         19        DO_FCALL                                      0  $22     
         20        INIT_METHOD_CALL                                         $22, 'getElementsByTagName'
         21        SEND_VAL_EX                                              'td'
         22        DO_FCALL                                      0  $23     
         23        ASSIGN                                                   !3, $23
   40    24        ASSIGN                                                   !4, <array>
   41    25        ASSIGN                                                   !5, <array>
   43    26      > FE_RESET_R                                       $27     !3, ->35
         27    > > FE_FETCH_R                                               $27, !6, ->35
   44    28    >   INIT_FCALL                                               'strtolower'
         29        FETCH_OBJ_R                                      ~29     !6, 'nodeValue'
         30        SEND_VAL                                                 ~29
         31        DO_ICALL                                         $30     
         32        ASSIGN_DIM                                               !5
         33        OP_DATA                                                  $30
   43    34      > JMP                                                      ->27
         35    >   FE_FREE                                                  $27
   47    36      > FE_RESET_R                                       $31     !2, ->61
         37    > > FE_FETCH_R                                       ~32     $31, !7, ->61
         38    >   ASSIGN                                                   !8, ~32
   48    39        IS_SMALLER                                               !8, 1
         40      > JMPZ                                                     ~34, ->42
         41    > > JMP                                                      ->37
   49    42    >   ASSIGN                                                   !9, <array>
   50    43      > FE_RESET_R                                       $36     !5, ->57
         44    > > FE_FETCH_R                                       ~37     $36, !10, ->57
         45    >   ASSIGN                                                   !11, ~37
   51    46        INIT_METHOD_CALL                                         !7, 'getElementsByTagName'
         47        SEND_VAL_EX                                              'td'
         48        DO_FCALL                                      0  $39     
         49        ASSIGN                                                   !12, $39
   52    50        INIT_METHOD_CALL                                         !12, 'item'
         51        SEND_VAR_EX                                              !11
         52        DO_FCALL                                      0  $42     
         53        FETCH_OBJ_R                                      ~43     $42, 'nodeValue'
         54        ASSIGN_DIM                                               !9, !10
         55        OP_DATA                                                  ~43
   50    56      > JMP                                                      ->44
         57    >   FE_FREE                                                  $36
   54    58        ASSIGN_DIM                                               !4
         59        OP_DATA                                                  !9
   47    60      > JMP                                                      ->37
         61    >   FE_FREE                                                  $31
   57    62        INIT_FCALL                                               'print_r'
         63        SEND_VAR                                                 !4
         64        DO_ICALL                                                 
         65      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.43 ms | 1404 KiB | 17 Q