3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = "<div class='parent'> <div class='title'>A Title</div> <div class='child'>some text</div> <div class='child'>some text</div> <div class='title'>A Title</div> <div class='child'>some text</div> <div class='child'>some text</div> </div>"; $dom = new DOMDocument(); $dom->loadHTML($xml); //$dom->loadXML($xml); $xpath = new DOMXPath($dom); $xpqueries = array( "//div[@class='parent']/div", "//div[@class='xparent']/div", // "comment()[last()]", // "/comment()[last()]", // "//comment()[last()]" ); foreach ($xpqueries as $xpquery) { $dnode = $xpath->query($xpquery); if ($dnode && $dnode->length > 0) { echo "query '{$xpquery}' results in {$dnode->length} nodes. '" . htmlentities($dnode->item(0)->nodeValue) . "' is the first item, '" . htmlentities($dnode->item($dnode->length - 1)->nodeValue) . "' is the last.<br />"; } else { echo "query '{$xpquery}' results in {$dnode->length} nodes.<br />"; } } return;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 59
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 59
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 51
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/3ckO5
function name:  (null)
number of ops:  62
compiled vars:  !0 = $xml, !1 = $dom, !2 = $xpath, !3 = $xpqueries, !4 = $xpquery, !5 = $dnode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Cdiv+class%3D%27parent%27%3E%0A++++%3Cdiv+class%3D%27title%27%3EA+Title%3C%2Fdiv%3E%0A++++%3Cdiv+class%3D%27child%27%3Esome+text%3C%2Fdiv%3E%0A++++%3Cdiv+class%3D%27child%27%3Esome+text%3C%2Fdiv%3E%0A++++%3Cdiv+class%3D%27title%27%3EA+Title%3C%2Fdiv%3E%0A++++%3Cdiv+class%3D%27child%27%3Esome+text%3C%2Fdiv%3E%0A++++%3Cdiv+class%3D%27child%27%3Esome+text%3C%2Fdiv%3E%0A%3C%2Fdiv%3E'
   10     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   11     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   13     7        NEW                                              $11     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $11
   15    11        ASSIGN                                                   !3, <array>
   23    12      > FE_RESET_R                                       $15     !3, ->59
         13    > > FE_FETCH_R                                               $15, !4, ->59
   25    14    >   INIT_METHOD_CALL                                         !2, 'query'
         15        SEND_VAR_EX                                              !4
         16        DO_FCALL                                      0  $16     
         17        ASSIGN                                                   !5, $16
   26    18      > JMPZ_EX                                          ~18     !5, ->22
         19    >   FETCH_OBJ_R                                      ~19     !5, 'length'
         20        IS_SMALLER                                       ~20     0, ~19
         21        BOOL                                             ~18     ~20
         22    > > JMPZ                                                     ~18, ->51
   28    23    >   ROPE_INIT                                     5  ~23     'query+%27'
         24        ROPE_ADD                                      1  ~23     ~23, !4
         25        ROPE_ADD                                      2  ~23     ~23, '%27+results+in+'
         26        FETCH_OBJ_R                                      ~21     !5, 'length'
         27        ROPE_ADD                                      3  ~23     ~23, ~21
         28        ROPE_END                                      4  ~22     ~23, '+nodes.++%27'
         29        INIT_FCALL                                               'htmlentities'
         30        INIT_METHOD_CALL                                         !5, 'item'
         31        SEND_VAL_EX                                              0
         32        DO_FCALL                                      0  $26     
         33        FETCH_OBJ_R                                      ~27     $26, 'nodeValue'
         34        SEND_VAL                                                 ~27
         35        DO_ICALL                                         $28     
         36        CONCAT                                           ~29     ~22, $28
         37        CONCAT                                           ~30     ~29, '%27+is+the+first+item%2C+%27'
         38        INIT_FCALL                                               'htmlentities'
         39        INIT_METHOD_CALL                                         !5, 'item'
         40        FETCH_OBJ_R                                      ~31     !5, 'length'
         41        SUB                                              ~32     ~31, 1
         42        SEND_VAL_EX                                              ~32
         43        DO_FCALL                                      0  $33     
         44        FETCH_OBJ_R                                      ~34     $33, 'nodeValue'
         45        SEND_VAL                                                 ~34
         46        DO_ICALL                                         $35     
         47        CONCAT                                           ~36     ~30, $35
         48        CONCAT                                           ~37     ~36, '%27+is+the+last.%3Cbr+%2F%3E'
         49        ECHO                                                     ~37
         50      > JMP                                                      ->58
   32    51    >   ROPE_INIT                                     5  ~40     'query+%27'
         52        ROPE_ADD                                      1  ~40     ~40, !4
         53        ROPE_ADD                                      2  ~40     ~40, '%27+results+in+'
         54        FETCH_OBJ_R                                      ~38     !5, 'length'
         55        ROPE_ADD                                      3  ~40     ~40, ~38
         56        ROPE_END                                      4  ~39     ~40, '+nodes.%3Cbr+%2F%3E'
         57        ECHO                                                     ~39
   23    58    > > JMP                                                      ->13
         59    >   FE_FREE                                                  $15
   36    60      > RETURN                                                   null
         61*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.02 ms | 1400 KiB | 15 Q