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();
精彩评论