So i have a load of images in html with the id images
. An example of one is like this:
<img id="images" src="video images/the wind rises.jpg" alt="" width="700" height="525" class="the-wind-rises1" />
And I am wanting to collect all the srcs(eg. video images/the wind rises.jpg
)
I have tried this. But it is not working how come?:
<?php
$html = file_get_contents('http://urlofwebsite.co.uk/xxxx');
function linkExtractor($html){
$imageArr = array();
$doc = new DOMDocument();
@$doc->loadHTML($html);
$images = $doc->getElementById('images');
foreach($images as $image) {
array_push($imageArr, $image->getAttribute('src'));
}
return $imageArr;
}
echo json_encode(array("images" => linkExtractor($html)));
?>
It is just returning:
{"images":[]}