I'm trying to extract the first src attribute of an image in a block of HTML text like this:
Lorem ipsum <img src="http://site.com/img.jpg" />consequat.
I have no problem creating the regex to match the src attribute, but how do I return the first matched src attribute, instead of replacing it?
From pouring over the PHP manual, it seems like preg_filter() would do the trick, but I can't rely on end users having PHP > 5.3.
All the other PHP regex functions seem to be variations of preg_match(), returning a boolean value, or preg_replace, which replaces the match with something. Is there a straightforward way to return a regex match in PHP?