3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'TAG' <html> <body> <table class="searchTable" cellspacing="0" cellpadding="5" style="width: 100%;"> <tbody> <tr> <th>Book</th> <th>Model Name</th> <th>Description</th> <th>Category</th> </tr> <tr> <td> <a onclick="getFullData( '', 'K0074', 'B2004' );" href="">K0072</a> </td> <td>B2004</td> <td>K0074 Description</td> <td>K0074 Category</td> </tr> </tbody> </table> </body> </html> TAG; $doc = new DOMDocument(); $doc->loadHTML($html); $tables = $doc->getElementsByTagName('table'); foreach ($tables as $table) { if ($table->getAttribute('class') !== 'searchTable') { continue; } $rows = $table->getElementsByTagName('tr'); foreach ($rows as $row) { $cells = $row->getElementsByTagName('td'); // Sanity check that we have four rows or skip it if (4 !== count($cells)) { continue; } // Sanity check that the first cell has a link inside it $firstCellLinks = $cells[0]->getElementsByTagName('a'); if (1 !== count($firstCellLinks)) { continue; } // Make sure the first link has an onclick attribute if (!$firstCellLinks[0]->hasAttribute('onclick')) { continue; } // Finally, get the contents of the cell. This can be simplified to a one-line but // I've expanded it to be more obvious. $firstCellLinkOnClick = $firstCellLinks[0]->attributes['onclick']->value; $firstCellLinkOnClickParamsAsString = preg_replace('/getFullData\(([^)]+)\);/', '$1', $firstCellLinkOnClick); $firstCellLinkOnClickParamsAsArray = str_getcsv($firstCellLinkOnClickParamsAsString, ',', "'"); print_r($firstCellLinkOnClickParamsAsArray); /* Array ( [0] => [1] => K0074 [2] => B2004 ) */ } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 72
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 72
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 70
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 70
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 42
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 70
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
filename:       /in/bv7I2
function name:  (null)
number of ops:  74
compiled vars:  !0 = $html, !1 = $doc, !2 = $tables, !3 = $table, !4 = $rows, !5 = $row, !6 = $cells, !7 = $firstCellLinks, !8 = $firstCellLinkOnClick, !9 = $firstCellLinkOnClickParamsAsString, !10 = $firstCellLinkOnClickParamsAsArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A+++%3Cbody%3E%0A++++++%3Ctable+class%3D%22searchTable%22+cellspacing%3D%220%22+cellpadding%3D%225%22+style%3D%22width%3A+100%25%3B%22%3E%0A+++++++++%3Ctbody%3E%0A++++++++++++%3Ctr%3E%0A+++++++++++++++%3Cth%3EBook%3C%2Fth%3E%0A+++++++++++++++%3Cth%3EModel+Name%3C%2Fth%3E%0A+++++++++++++++%3Cth%3EDescription%3C%2Fth%3E%0A+++++++++++++++%3Cth%3ECategory%3C%2Fth%3E%0A++++++++++++%3C%2Ftr%3E%0A++++++++++++%3Ctr%3E%0A+++++++++++++++%3Ctd%3E%0A++++++++++++++++++%3Ca+onclick%3D%22getFullData%28+%27%27%2C+%27K0074%27%2C+%27B2004%27+%29%3B%22+href%3D%22%22%3EK0072%3C%2Fa%3E%0A+++++++++++++++%3C%2Ftd%3E%0A+++++++++++++++%3Ctd%3EB2004%3C%2Ftd%3E%0A+++++++++++++++%3Ctd%3EK0074+Description%3C%2Ftd%3E%0A+++++++++++++++%3Ctd%3EK0074+Category%3C%2Ftd%3E%0A++++++++++++%3C%2Ftr%3E%0A++++++++%3C%2Ftbody%3E%0A++++++++%3C%2Ftable%3E%0A++++%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   28     1        NEW                                              $12     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $12
   29     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   30     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'table'
          9        DO_FCALL                                      0  $16     
         10        ASSIGN                                                   !2, $16
   31    11      > FE_RESET_R                                       $18     !2, ->72
         12    > > FE_FETCH_R                                               $18, !3, ->72
   32    13    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         14        SEND_VAL_EX                                              'class'
         15        DO_FCALL                                      0  $19     
         16        IS_NOT_IDENTICAL                                         $19, 'searchTable'
         17      > JMPZ                                                     ~20, ->19
   33    18    > > JMP                                                      ->12
   36    19    >   INIT_METHOD_CALL                                         !3, 'getElementsByTagName'
         20        SEND_VAL_EX                                              'tr'
         21        DO_FCALL                                      0  $21     
         22        ASSIGN                                                   !4, $21
   37    23      > FE_RESET_R                                       $23     !4, ->70
         24    > > FE_FETCH_R                                               $23, !5, ->70
   38    25    >   INIT_METHOD_CALL                                         !5, 'getElementsByTagName'
         26        SEND_VAL_EX                                              'td'
         27        DO_FCALL                                      0  $24     
         28        ASSIGN                                                   !6, $24
   41    29        COUNT                                            ~26     !6
         30        IS_NOT_IDENTICAL                                         ~26, 4
         31      > JMPZ                                                     ~27, ->33
   42    32    > > JMP                                                      ->24
   46    33    >   FETCH_DIM_R                                      ~28     !6, 0
         34        INIT_METHOD_CALL                                         ~28, 'getElementsByTagName'
         35        SEND_VAL_EX                                              'a'
         36        DO_FCALL                                      0  $29     
         37        ASSIGN                                                   !7, $29
   47    38        COUNT                                            ~31     !7
         39        IS_NOT_IDENTICAL                                         ~31, 1
         40      > JMPZ                                                     ~32, ->42
   48    41    > > JMP                                                      ->24
   52    42    >   FETCH_DIM_R                                      ~33     !7, 0
         43        INIT_METHOD_CALL                                         ~33, 'hasAttribute'
         44        SEND_VAL_EX                                              'onclick'
         45        DO_FCALL                                      0  $34     
         46        BOOL_NOT                                         ~35     $34
         47      > JMPZ                                                     ~35, ->49
   53    48    > > JMP                                                      ->24
   58    49    >   FETCH_DIM_R                                      ~36     !7, 0
         50        FETCH_OBJ_R                                      ~37     ~36, 'attributes'
         51        FETCH_DIM_R                                      ~38     ~37, 'onclick'
         52        FETCH_OBJ_R                                      ~39     ~38, 'value'
         53        ASSIGN                                                   !8, ~39
   59    54        INIT_FCALL                                               'preg_replace'
         55        SEND_VAL                                                 '%2FgetFullData%5C%28%28%5B%5E%29%5D%2B%29%5C%29%3B%2F'
         56        SEND_VAL                                                 '%241'
         57        SEND_VAR                                                 !8
         58        DO_ICALL                                         $41     
         59        ASSIGN                                                   !9, $41
   60    60        INIT_FCALL                                               'str_getcsv'
         61        SEND_VAR                                                 !9
         62        SEND_VAL                                                 '%2C'
         63        SEND_VAL                                                 '%27'
         64        DO_ICALL                                         $43     
         65        ASSIGN                                                   !10, $43
   62    66        INIT_FCALL                                               'print_r'
         67        SEND_VAR                                                 !10
         68        DO_ICALL                                                 
   37    69      > JMP                                                      ->24
         70    >   FE_FREE                                                  $23
   31    71      > JMP                                                      ->12
         72    >   FE_FREE                                                  $18
   72    73      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.74 ms | 1021 KiB | 16 Q