Get img src using PHP

Use a HTML parser like DomDocument parsing to get image src attribute value.


<php

$html = '<div id="chart_div"><img src="images.png"</div>';
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
$imagename = "images/google_chart.png";
foreach ($tags as $tag) {
         $img_src = $tag->getAttribute('src');
         file_put_contents($imagename, file_get_contents($img_src));
}
echo $result ='<img src="'.$imagename.'">';
}
?>





No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...