开发者

regexp to remove anchor with specific class and it's content?

<a class="rsswidget" href="http:/domain.com/feed/" title="RSS">
<img style="border:0" width="14" height="14" src="http://domain.com/images/rss.png" alt="RSS">
</a>

What regexp do I need to get rid of this entire anchor, inclusiveley the image inside? Unfortunately I'm a regexp noob and so I need your help. Thank you very much.

return preg_replace('#<a+class="rsswidget"[^>]*>开发者_C百科;.*?</a>#is', '', $content);


That's almost right. But the + quantifies only the a. You wanted to use [^>]+ at that position:

preg_replace('#<a[^>]+class="rsswidget"[^>]*>.*?</a>#is',

To avoid any regex-for-html-whatever-downvoting, this would be the QueryPath alternative:

return qp($html)->find("a.rsswidget")->remove()->writeHTML();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜