3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html=<<<HTML <html> <body> <table id="news" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="539" height="35"><span><strong>Info to Extract</strong></span></td> </tr> <tr> <td height="35" class="texto10">Martes, 02 de Octubre de 2012 | Autor: Trovert</td> </tr> <tr> <td height="35" class="texto12Gris"><p><strong>Info To extract</strong></p> <p><strong>&nbsp;</strong></p> <p><strong>Casa de Gobierno: (a 9 cuadras del hostel)</strong></p> <img title="title" src="../images/theimage.jpg" width="400" height="266" /> </td> </tr> </table> </body> </html> HTML; function walkNode($node) { $str=""; if($node->nodeType==XML_TEXT_NODE) { $str.=$node->nodeValue; } elseif(strtolower($node->nodeName)=="img") { $str.='<img src="'.$node->attributes->getNamedItem("src")->nodeValue.'" />'; } if($node->firstChild) $str.=walkNode($node->firstChild); if($node->nextSibling) $str.=walkNode($node->nextSibling); return $str; } $dom=new DOMDocument(); $dom->loadHTML($html); $xpath=new DOMXPath($dom); $tds=$xpath->query('//table[@id="news"]//tr[position()>0]/td'); foreach($tds as $td) { echo walkNode($td->firstChild); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/mIZer
function name:  (null)
number of ops:  26
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $tds, !4 = $td
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A%3Cbody%3E%0A%3Ctable+id%3D%22news%22+width%3D%22100%25%22+border%3D%220%22+cellspacing%3D%220%22+cellpadding%3D%220%22%3E%0A++++%3Ctr%3E%0A++++++++%3Ctd+width%3D%22539%22+height%3D%2235%22%3E%3Cspan%3E%3Cstrong%3EInfo+to+Extract%3C%2Fstrong%3E%3C%2Fspan%3E%3C%2Ftd%3E%0A++++%3C%2Ftr%3E%0A++++%3Ctr%3E%0A++++++++%3Ctd+height%3D%2235%22+class%3D%22texto10%22%3EMartes%2C+02+de+Octubre+de+2012++%7C+Autor%3A+Trovert%3C%2Ftd%3E%0A++++%3C%2Ftr%3E%0A++++%3Ctr%3E%0A++++++++%3Ctd+height%3D%2235%22+class%3D%22texto12Gris%22%3E%3Cp%3E%3Cstrong%3EInfo+To+extract%3C%2Fstrong%3E%3C%2Fp%3E%0A++++++++++++%3Cp%3E%3Cstrong%3E%26nbsp%3B%3C%2Fstrong%3E%3C%2Fp%3E%0A++++++++++++%3Cp%3E%3Cstrong%3ECasa+de+Gobierno%3A+%28a+9+cuadras+del+hostel%29%3C%2Fstrong%3E%3C%2Fp%3E%0A++++++++++++%3Cimg+title%3D%22title%22+src%3D%22..%2Fimages%2Ftheimage.jpg%22+width%3D%22400%22+height%3D%22266%22+%2F%3E%0A++++++++%3C%2Ftd%3E%0A++++%3C%2Ftr%3E%0A%3C%2Ftable%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   40     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   41     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   42     7        NEW                                              $10     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $10
   43    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2F%2Ftable%5B%40id%3D%22news%22%5D%2F%2Ftr%5Bposition%28%29%3E0%5D%2Ftd'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   44    15      > FE_RESET_R                                       $15     !3, ->24
         16    > > FE_FETCH_R                                               $15, !4, ->24
   46    17    >   INIT_FCALL                                               'walknode'
         18        FETCH_OBJ_R                                      ~16     !4, 'firstChild'
         19        SEND_VAL                                                 ~16
         20        DO_FCALL                                      0  $17     
         21        ECHO                                                     $17
   47    22        ECHO                                                     '%0A'
   44    23      > JMP                                                      ->16
         24    >   FE_FREE                                                  $15
   48    25      > RETURN                                                   1

Function walknode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 30
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
Branch analysis from position: 30
Branch analysis from position: 22
filename:       /in/mIZer
function name:  walkNode
number of ops:  40
compiled vars:  !0 = $node, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, ''
   27     2        FETCH_OBJ_R                                      ~3      !0, 'nodeType'
          3        IS_EQUAL                                                 ~3, 3
          4      > JMPZ                                                     ~4, ->8
   29     5    >   FETCH_OBJ_R                                      ~5      !0, 'nodeValue'
          6        ASSIGN_OP                                     8          !1, ~5
          7      > JMP                                                      ->22
   31     8    >   INIT_FCALL                                               'strtolower'
          9        FETCH_OBJ_R                                      ~7      !0, 'nodeName'
         10        SEND_VAL                                                 ~7
         11        DO_ICALL                                         $8      
         12        IS_EQUAL                                                 $8, 'img'
         13      > JMPZ                                                     ~9, ->22
   33    14    >   FETCH_OBJ_R                                      ~10     !0, 'attributes'
         15        INIT_METHOD_CALL                                         ~10, 'getNamedItem'
         16        SEND_VAL_EX                                              'src'
         17        DO_FCALL                                      0  $11     
         18        FETCH_OBJ_R                                      ~12     $11, 'nodeValue'
         19        CONCAT                                           ~13     '%3Cimg+src%3D%22', ~12
         20        CONCAT                                           ~14     ~13, '%22+%2F%3E'
         21        ASSIGN_OP                                     8          !1, ~14
   35    22    >   FETCH_OBJ_R                                      ~16     !0, 'firstChild'
         23      > JMPZ                                                     ~16, ->30
         24    >   INIT_FCALL_BY_NAME                                       'walkNode'
         25        CHECK_FUNC_ARG                                           
         26        FETCH_OBJ_FUNC_ARG                               $17     !0, 'firstChild'
         27        SEND_FUNC_ARG                                            $17
         28        DO_FCALL                                      0  $18     
         29        ASSIGN_OP                                     8          !1, $18
   36    30    >   FETCH_OBJ_R                                      ~20     !0, 'nextSibling'
         31      > JMPZ                                                     ~20, ->38
         32    >   INIT_FCALL_BY_NAME                                       'walkNode'
         33        CHECK_FUNC_ARG                                           
         34        FETCH_OBJ_FUNC_ARG                               $21     !0, 'nextSibling'
         35        SEND_FUNC_ARG                                            $21
         36        DO_FCALL                                      0  $22     
         37        ASSIGN_OP                                     8          !1, $22
   37    38    > > RETURN                                                   !1
   38    39*     > RETURN                                                   null

End of function walknode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.97 ms | 1407 KiB | 16 Q