3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $i=1; while ($i<=5) { # code... $url = 'http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#'.$i; echo $url; $html= file_get_contents($url); $dom = new DOMDocument(); @$dom->loadHTML($html); $xPath = new DOMXPath($dom); $classname="zg_title"; $elements = $xPath->query("//*[contains(@class, '$classname')]"); foreach ($elements as $e) { $lnk = $e->getAttribute('href'); $e->setAttribute("href", "http://www.amazon.in".$lnk); $newdoc = new DOMDocument; $e = $newdoc->importNode($e, true); $newdoc->appendChild($e); $html = $newdoc->saveHTML(); echo $html; } $i++; } ?>
Output for 5.3.19 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19, 7.0.4, 7.0.20, 7.1.5 - 7.2.0
http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#1 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#1): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#2 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#2): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#3 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#3): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#4 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#4): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#5 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#5): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/JH6Gk on line 9
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
http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#1 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#1): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#2 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#2): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#3 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#3): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#4 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#4): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#5 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9 Warning: file_get_contents(http://www.amazon.in/gp/bestsellers/electronics/ref=zg_bs_nav_0#5): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/JH6Gk on line 9