I am trying to extract the src value from a tag, so far I seem to be able to extract the string between the src value and the final quotation mark in the string
String:
<img border="0" src="http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif" width="89" height="31" alt="">
e.g. in PHP:
preg_match('/src=\"(.*)\"/', $row->find('a img',0), $matches);
if($matches){
echo $matches[0];
}
prints out
src="http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif" width="89" height="31" alt=""
but what i really want printed is...
src="http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif"
or if possible just...
http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif
what should I be adding to the regex? Thanks
You were actually very close >>
Yours: preg_match('/src=\"(.*)\"/', $row->find('a img',0), $matches);
Correct one: preg_match('/src=\"(.*?)\"/', $row->find('a img',0), $matches);
By adding ?
you make request for match .*
lazy, which means it will match anything until needed, not anything until can. Without lazy operator it will stop in front of last double-quote "
, which is behind alt="
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With