3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = ' <div class="class"> <p>A little paragraph</p> <a href="#"><img src="/test.jpg"/></a> <p>Another paragraph</p> <ul> <li>1</li> <li>2</li> </ul> </div>'; $dom = new DomDocument(); @$dom->loadHTML($html); $xpath = new DOMXpath($dom); $masterNode = $xpath->query('//div[@class="class"]'); #It returns DOMNodeList obj # Now from master node we gonna pick what we want. # Also, $masterNode->item(1) is a context for this query. $paragraphNodes = $xpath->query('p', $masterNode->item(0)); foreach ($paragraphNodes as $paragraphElement) { echo $paragraphElement->nodeValue . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/9CYCs
function name:  (null)
number of ops:  33
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $masterNode, !4 = $paragraphNodes, !5 = $paragraphElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0A%3Cdiv+class%3D%22class%22%3E%0A++%3Cp%3EA+little+paragraph%3C%2Fp%3E%0A++%3Ca+href%3D%22%23%22%3E%3Cimg+src%3D%22%2Ftest.jpg%22%2F%3E%3C%2Fa%3E%0A++%3Cp%3EAnother+paragraph%3C%2Fp%3E%0A++%3Cul%3E%0A++++%3Cli%3E1%3C%2Fli%3E%0A++++%3Cli%3E2%3C%2Fli%3E%0A++%3C%2Ful%3E%0A%3C%2Fdiv%3E'
   14     1        NEW                                              $7      'DomDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   15     4        BEGIN_SILENCE                                    ~10     
          5        INIT_METHOD_CALL                                         !1, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        END_SILENCE                                              ~10
   16     9        NEW                                              $12     'DOMXpath'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $12
   17    13        INIT_METHOD_CALL                                         !2, 'query'
         14        SEND_VAL_EX                                              '%2F%2Fdiv%5B%40class%3D%22class%22%5D'
         15        DO_FCALL                                      0  $15     
         16        ASSIGN                                                   !3, $15
   21    17        INIT_METHOD_CALL                                         !2, 'query'
         18        SEND_VAL_EX                                              'p'
         19        INIT_METHOD_CALL                                         !3, 'item'
         20        SEND_VAL_EX                                              0
         21        DO_FCALL                                      0  $17     
         22        SEND_VAR_NO_REF_EX                                       $17
         23        DO_FCALL                                      0  $18     
         24        ASSIGN                                                   !4, $18
   23    25      > FE_RESET_R                                       $20     !4, ->31
         26    > > FE_FETCH_R                                               $20, !5, ->31
   24    27    >   FETCH_OBJ_R                                      ~21     !5, 'nodeValue'
         28        CONCAT                                           ~22     ~21, '%0A'
         29        ECHO                                                     ~22
   23    30      > JMP                                                      ->26
         31    >   FE_FREE                                                  $20
   25    32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.71 ms | 1399 KiB | 13 Q