vinod kumar vinod kumar - 2 months ago 7
PHP Question

How to get image from any website with url

I need to get image url only from any webpage with php nothing else.how can i get image url please help.

I have try

file_get_contents(url);
but its not usefull for me.

Thanks in advance

Ram Ram
Answer
$url="http://example.com";
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) {
echo $tag->getAttribute('src');
}

Check this code its working for me.

Comments