I got this bunch of strings from RSS and i want to extract SRC (source) value from IMG tag.
<a title="test01" rel="lightbox[pics5]" href="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg"><img class="attachment wp-att-7 alignleft" src="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg" alt="test01" width="390" height="200" /></a><a title="test01" rel="lightbox[pics5]" href="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg"><img class="attachment wp-att-7" src="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg" alt="test01" width="390" height="200" /></a></p><p>Test image</p>
How can i do that? I'm using PHP regular expression.
Thanks in advance.
-darien
Try:
<img\s.*?src=("[^"]*"|\S*)
with the 'ignore case' option set if the 'img' and 'src' could be in uppercase. The value you want is in match group #1.
This picked out the two instances in your test string.
Susan
thanks for the help.
I found my own solution to this and just share it to everyone.
$imgSrcPattern = '/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'\s>]*)/i';