3v4l.org

run code in 300+ PHP versions simultaneously
<?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++; } ?>

preferences:
40.09 ms | 402 KiB | 5 Q