Scraping image URLs from HTML with DOMDocument

azarulez

New Member
I'm trying to grab all the images from a page and echo them out on my page.\[code\]$html = file_get_contents("http://www.site.com/");$doc = new DOMDocument();@$doc->loadHTML($html);$imgs = $doc->getElementsByTagName("img");for ($i = 0; $i < $imgs->length; $i++) { $image = $imgs->item($i); $src = http://stackoverflow.com/questions/10561375/$image->getAttribute("src"); echo '<img src="' . $src . '" /><br />';}\[/code\]I'm only able to grab the first one for some reason. Why is this?
 
Back
Top