With PHP, how can I isolate the contents of the src attribute from $foo? The end result I\'m looking for would give me just \"http://example.com/img/image.jpg\"
lets assume i use
$text ='
';
in
getTextBetween('src="','"',$text);
the codes will return :
blabla.jpg" alt="blabla"
which is wrong, we want the codes to return the text between the attribute value quotes i.e attr = "value".
so
function getTextBetween($start, $end, $text)
{
// explode the start string
$first_strip= end(explode($start,$text,2));
// explode the end string
$final_strip = explode($end,$first_strip)[0];
return $final_strip;
}
does the trick!.
Try
getTextBetween('src="','"',$text);
will return:
blabla.jpg
Thanks all the same , because your solution gave me an insight to the final solution .