The code below shows how to extract an 'http:'//' image based tag.
Then display them, and modify the HTML to show you what it found.
<?php
$total = 0;
$sample_HTML = "
<html>
<body>
<h2>[TOTAL GOES HERE]</h2>
<p>
This is a sample piece of HTML<br>
blah blah <img src='http://api.flattr.com/button/flattr-badge-large.png' [title0]><br>
trash talk every place you look
</p>
<p>
more blah blah<br>
<img src='http://ca2.php.net/images/php.gif' [title1]><br>
apple pear plum cherry
</p>
<p>
<a href='www.google.com'>Google Chrome<img src='http://www.google.com/images/icons/product/chrome-48.png' [title2]></a>
But are there any COOKIES !!
</p>
</body>
</html>
";
echo "<hr>This is what it looks like in RAW form<hr>";
echo $sample_HTML;
echo "<hr>";
$new_HTML = $sample_HTML;
preg_match_all('!
http://.+\.(?:jpe?g|png|gif)!Ui' , $sample_HTML , $match);
$total = count($match[0], true);
echo "Total: $total<br>\n";
for ($i = 0; $i < $total; $i++) {
$str = $match[0][$i];
echo "image$i: $str<br>\n";
$new_HTML = str_replace("[title$i]", "title='$str'", $new_HTML);
}
echo "<hr>";
// Show results
$new_HTML = str_replace("[TOTAL GOES HERE]", "Total Count: $total", $new_HTML);
$new_HTML = str_replace("</body>", "<h2>More your cursor over the images</h2></body>", $new_HTML);
echo "<hr>This is what it looks like in PROCESSED form<hr>";
echo $new_HTML;
?>
What do you want for nothing !