假设我们有这样的 HTML 代码。我们需要获取<a href=""></a>
其中不包含img
标签的所有标签。
<a href="http://domain1.com"><span>Here is link</span></a>
<a href="http://domain2.com" title="">Hello</a>
<a href="http://domain3.com" title=""><img src="" /></a>
<a href="http://domain4" title=""> I'm the image <img src="" /> yeah</a>
我正在使用这个正则表达式来查找所有 a 标签链接:
preg_match_all("!<a[^>]+href=\"?'?([^ \"'>]+)\"?'?[^>]*>(.*?)</a>!is", $content, $out);
我可以这样修改它:
preg_match_all("!<a[^>]+href=\"?'?([^ \"'>]+)\"?'?[^>]*>([^<>]+?)</a>!is", $content, $out);
但是我怎么能告诉它排除包含<img
子字符串的结果<a href=""></a>
呢?