3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<!doctype html> <html> <head> <title>test</title> </head> <body> <a id="1"> <b>value1</b> <b>value2</b> </a> <a id="2"> <b>value1</b> </a> </body> </html>'; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXpath($doc); $nodes = $xpath->query("//b[contains(., 'value1')] | //b[contains(., 'value2')]"); $parent_id = $nodes->item(0)->parentNode->getAttribute("id"); echo $parent_id;

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
152.53 ms | 2254 KiB | 8 Q