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); $xpath = new DOMXPath($dom); $xpqueries = array( "//div[@class='parent']/div", "//div[@class='xparent']/div", ); 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;
Output for git.master, git.master_jit, rfc.property-hooks
query '//div[@class='parent']/div' results in 6 nodes. 'A Title' is the first item, 'some text' is the last.<br />query '//div[@class='xparent']/div' results in 0 nodes.<br />

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.3 ms | 401 KiB | 8 Q