natatkinson
2/15/2014 - 5:42 PM

List all images from a page

List all images from a page

$page = "http://www.steepleweb.com";
$html = file_get_contents($page);

$dom = new domDocument;

/*** load the html into the object ***/
$dom->loadHTML($html);

/*** discard white space ***/
$dom->preserveWhiteSpace = false;

$images = $dom->getElementsByTagName('img');

foreach($images as $img)
    {
    	$url = $img->getAttribute('src');	
    	$alt = $img->getAttribute('alt');
    	$width = (int)$img->getAttribute('width');
    	$height = (int)$img->getAttribute('height');	
    	echo "Title: $alt<br>$url<br>$width<br>$height<br>";
    }