Utiliza expresiones regulares siempre que puedas.........
EJ (hace otra cosa pero sirve)
Código PHP:
<?php
// parser de TAGS
// Example string
$str = "Let's find the stuff <bla>in between</bla> these two previous brackets";
// Let's perform the regex
$do = preg_match("/<bla>(.*)<\/bla>/", $str, $matches);
// Check if regex was successful
if ($do = true) {
// Matched something, show the matched string
echo htmlentities($matches['0']);
// Also how the text in between the tags
echo '<br />' . $matches['1'];
} else {
// No Match
echo "Couldn't find a match";
}
?>
En tu caso el $do seria algo como ....
$do =
preg_match("/<img(.*)>/", $str, $matches); // esto busca entre
<img y
>
Luego deberias buscar dentro de $matches el src=" " o bien buscar eso mismo de una.
preg_match_all busca no solo la primera coincidencia sino todas