I want to parse image from a website and output into php file. I'm getting element by class and now i want to get it attribute src and then to print out the image. How can i achieve it?
$htmlDoc = new DOMDocument();
$htmlDoc->loadHTML($result);
$simpleHtml = simplexml_import_dom($htmlDoc);
$image = $simpleHtml->xpath('//img[@class^="pdt-thumbnail-image"]@src');
foreach($image as $img) {
echo '<img =src"'.$img[0].'">';
}
HTML Structure
<img role="presentation" class="pdt-thumbnail-image is-active lazy-image is-loaded" data-reactid="174" src="https://d2xngy2dw7hums.cloudfront.net/media/photos/products/2016/08/04/samsung_car_fast_charger_1470291965_408c5b7a.jpg">
Output error:
Invalid argument supplied for foreach()