3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <table> <tbody id="threadbits_forum_26"> <tr> <td class="alt1"> <a href="http://www.example1.com">test1</a> </td> </tr> <tr> <td class="alt1"> <a href="http://www.example2.com">test2</a> </td> </tr> <tr> <td class="alt1"> <a href="http://www.example3.com">test3</a> </td> </tr> <tr> <td class="alt1"> <a href="http://www.example4.com">test4</a> </td> </tr> <tr> <td class="alt1"> <a href="http://www.example5.com">test5</a> </td> </tr> <tr> <td class="alt1"> <a href="http://www.example6.com">test6</a> </td> </tr> </tbody> </table> HTML; $dom=new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); $result = ''; foreach ($xpath->evaluate("//td[@class='alt1']/a") as $i => $node) { // target a tags that have <td class="alt1"> as parent if ($i > 1) { // disqualify first two nodes $result .= "\t<li class=\"itemtitle\"><a href=\"{$node->getAttribute('href')}\" target=\"_blank\">{$node->nodeValue}</a></li>\n"; if ($i == 12) { break; } // set a limit of 10 rows of data (#3 to #13) } } if ($result) { echo "<ul>\n$result</ul>"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 34
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 34
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 33
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 33
Branch analysis from position: 34
Branch analysis from position: 34
filename:       /in/Y8cjm
function name:  (null)
number of ops:  41
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $result, !4 = $node, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Ctable%3E%0A++++%3Ctbody+id%3D%22threadbits_forum_26%22%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd+class%3D%22alt1%22%3E%0A++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fwww.example1.com%22%3Etest1%3C%2Fa%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd+class%3D%22alt1%22%3E%0A++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fwww.example2.com%22%3Etest2%3C%2Fa%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd+class%3D%22alt1%22%3E%0A++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fwww.example3.com%22%3Etest3%3C%2Fa%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd+class%3D%22alt1%22%3E%0A++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fwww.example4.com%22%3Etest4%3C%2Fa%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd+class%3D%22alt1%22%3E%0A++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fwww.example5.com%22%3Etest5%3C%2Fa%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Ctd+class%3D%22alt1%22%3E%0A++++++++++++++++%3Ca+href%3D%22http%3A%2F%2Fwww.example6.com%22%3Etest6%3C%2Fa%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++%3C%2Ftbody%3E%0A%3C%2Ftable%3E'
   39     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   40     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   41     7        NEW                                              $11     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $11
   42    11        ASSIGN                                                   !3, ''
   43    12        INIT_METHOD_CALL                                         !2, 'evaluate'
         13        SEND_VAL_EX                                              '%2F%2Ftd%5B%40class%3D%27alt1%27%5D%2Fa'
         14        DO_FCALL                                      0  $15     
         15      > FE_RESET_R                                       $16     $15, ->34
         16    > > FE_FETCH_R                                       ~17     $16, !4, ->34
         17    >   ASSIGN                                                   !5, ~17
   44    18        IS_SMALLER                                               1, !5
         19      > JMPZ                                                     ~19, ->33
   45    20    >   ROPE_INIT                                     5  ~23     '%09%3Cli+class%3D%22itemtitle%22%3E%3Ca+href%3D%22'
         21        INIT_METHOD_CALL                                         !4, 'getAttribute'
         22        SEND_VAL_EX                                              'href'
         23        DO_FCALL                                      0  $20     
         24        ROPE_ADD                                      1  ~23     ~23, $20
         25        ROPE_ADD                                      2  ~23     ~23, '%22+target%3D%22_blank%22%3E'
         26        FETCH_OBJ_R                                      ~21     !4, 'nodeValue'
         27        ROPE_ADD                                      3  ~23     ~23, ~21
         28        ROPE_END                                      4  ~22     ~23, '%3C%2Fa%3E%3C%2Fli%3E%0A'
         29        ASSIGN_OP                                     8          !3, ~22
   46    30        IS_EQUAL                                                 !5, 12
         31      > JMPZ                                                     ~27, ->33
         32    > > JMP                                                      ->34
   43    33    > > JMP                                                      ->16
         34    >   FE_FREE                                                  $16
   49    35      > JMPZ                                                     !3, ->40
   50    36    >   ROPE_INIT                                     3  ~29     '%3Cul%3E%0A'
         37        ROPE_ADD                                      1  ~29     ~29, !3
         38        ROPE_END                                      2  ~28     ~29, '%3C%2Ful%3E'
         39        ECHO                                                     ~28
   51    40    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.46 ms | 1012 KiB | 13 Q