3v4l.org

run code in 500+ PHP versions simultaneously
<?php $body = '<p><a href="#">link</a><a href="#">another</a><button>button</button><i>some text</i></p>'; $dom = new DOMDocument; @$dom->loadHTML("<?xml version='1.0' encoding='UTF-8'?><body>$body</body>"); $xpath = new DOMXPath($dom); $nodelist = $xpath->query('//a | //button'); // echo "Length is : " . $nodelist->length, PHP_EOL; foreach ($nodelist as $index => $node) { echo "Node $index is $node->nodeName" . PHP_EOL; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Length is : 3 Node 0 is a Node 1 is a Node 2 is button

preferences:
91.75 ms | 1253 KiB | 4 Q