3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<book pages="2"> <page n="1" /> <entry> One </entry> <entry> Two </entry> <entry> Three </entry> <page n="2" /> <entry> Ten </entry> <entry> Eleven </entry> <entry> Twelve </entry> <endpages /> </book>'; $pageNo = 2; $dom = new DOMDocument("1.0", "UTF-8"); $dom->loadXML($xml); $xp = new DOMXPath($dom); $list = $xp->query("/book/page[@n='" . $pageNo . "']/following-sibling::*"); foreach ($list as $node) { if ($node->nodeName == 'page' || $node->nodeName == 'endpages') { break; } printf("%s\n", $node->textContent); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 36
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 36
Branch analysis from position: 22
2 jumps found. (Code = 47) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 28
Branch analysis from position: 36
Branch analysis from position: 36
filename:       /in/T2iDc
function name:  (null)
number of ops:  38
compiled vars:  !0 = $xml, !1 = $pageNo, !2 = $dom, !3 = $xp, !4 = $list, !5 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cbook+pages%3D%222%22%3E%0A++++%3Cpage+n%3D%221%22+%2F%3E%0A++++%3Centry%3E%0A++++++++One%0A++++%3C%2Fentry%3E%0A++++%3Centry%3E%0A++++++++Two%0A++++%3C%2Fentry%3E%0A++++%3Centry%3E%0A++++++++Three%0A++++%3C%2Fentry%3E%0A++++%3Cpage+n%3D%222%22+%2F%3E%0A++++%3Centry%3E%0A++++++++Ten%0A++++%3C%2Fentry%3E%0A++++%3Centry%3E%0A++++++++Eleven%0A++++%3C%2Fentry%3E%0A++++%3Centry%3E%0A++++++++Twelve%0A++++%3C%2Fentry%3E%0A++++%3Cendpages+%2F%3E%0A%3C%2Fbook%3E'
   27     1        ASSIGN                                                   !1, 2
   29     2        NEW                                              $8      'DOMDocument'
          3        SEND_VAL_EX                                              '1.0'
          4        SEND_VAL_EX                                              'UTF-8'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $8
   30     7        INIT_METHOD_CALL                                         !2, 'loadXML'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   32    10        NEW                                              $12     'DOMXPath'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !3, $12
   34    14        INIT_METHOD_CALL                                         !3, 'query'
         15        CONCAT                                           ~15     '%2Fbook%2Fpage%5B%40n%3D%27', !1
         16        CONCAT                                           ~16     ~15, '%27%5D%2Ffollowing-sibling%3A%3A%2A'
         17        SEND_VAL_EX                                              ~16
         18        DO_FCALL                                      0  $17     
         19        ASSIGN                                                   !4, $17
   36    20      > FE_RESET_R                                       $19     !4, ->36
         21    > > FE_FETCH_R                                               $19, !5, ->36
   37    22    >   FETCH_OBJ_R                                      ~20     !5, 'nodeName'
         23        IS_EQUAL                                         ~21     ~20, 'page'
         24      > JMPNZ_EX                                         ~21     ~21, ->28
         25    >   FETCH_OBJ_R                                      ~22     !5, 'nodeName'
         26        IS_EQUAL                                         ~23     ~22, 'endpages'
         27        BOOL                                             ~21     ~23
         28    > > JMPZ                                                     ~21, ->30
   38    29    > > JMP                                                      ->36
   41    30    >   INIT_FCALL                                               'printf'
         31        SEND_VAL                                                 '%25s%0A'
         32        FETCH_OBJ_R                                      ~24     !5, 'textContent'
         33        SEND_VAL                                                 ~24
         34        DO_ICALL                                                 
   36    35      > JMP                                                      ->21
         36    >   FE_FREE                                                  $19
   42    37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.07 ms | 1405 KiB | 15 Q