3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php //a URL you want to retrieve $my_url = 'http://www.digg.com'; $html = file_get_contents($my_url); $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); //Put your XPath Query here $my_xpath_query = "/html/body/span[./preceding-sibling::span[@itemprop='currency']]"; $result_rows = $xpath->query($my_xpath_query); //here we loop through our results (a DOMDocument Object) foreach ($result_rows as $result_object){ echo $result_object->childNodes->item(0)->nodeValue; }
based on KjE59
Output for 5.3.17 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19, 7.0.4, 7.0.20, 7.1.5 - 7.2.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/Y2hAp on line 4 Warning: file_get_contents(http://www.digg.com): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/Y2hAp on line 4 Warning: DOMDocument::loadHTML(): Empty string supplied as input in /in/Y2hAp on line 6
Output for 5.5.24 - 5.5.32, 5.5.34 - 5.6.17, 5.6.20 - 7.0.3, 7.0.5 - 7.0.6, 7.1.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/Y2hAp on line 4 Warning: file_get_contents(http://www.digg.com): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/Y2hAp on line 4 Warning: DOMDocument::loadHTML(): Empty string supplied as input in /in/Y2hAp on line 6