我正在尝试从标签中提取 src 值,
到目前为止,我似乎能够提取 src 值和字符串中最后一个引号之间的字符串
String:
<img border="0" src="http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif" width="89" height="31" alt="">
例如在 PHP 中:
preg_match('/src=\"(.*)\"/', $row->find('a img',0), $matches);
if($matches){
echo $matches[0];
}
打印出来
src="http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif" width="89" height="31" alt=""
但我真正想要打印的是......
src="http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif"
或者如果可能的话只是...
http://i.bookfinder.com/about/booksellers/logo_borderless/amazon_uk.gif
我应该在正则表达式中添加什么?谢谢
你们实际上非常接近>>
Yours: preg_match('/src=\"(.*)\"/', $row->find('a img',0), $matches);
Correct one: preg_match('/src=\"(.*?)\"/', $row->find('a img',0), $matches);
通过增加?
您提出匹配请求.*
惰性的,这意味着它会匹配任何东西直到需要,而不是任何东西直到可以。如果没有惰性运算符,它将停在最后一个双引号前面"
,后面就是alt="
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)