3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); }
based on lJ61l
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
Ten Eleven Twelve