-1
排除EM标签我有这样的HTML文本:从正则表达式匹配
<strong><em>La congiura della pietra nera</em></strong>
<p><a href="xxxxx">
<img class="alignleft size-medium wp-image-75372" title="mytitle"
src="my.jpg" alt="" width="247" height="350"></a>
<strong>Trama:</strong> La storia ruota attorno ad una setta di guerrieri depositaria dei più arcani segreti.</p>
我需要做的一些字prey_replace,我用这个正则表达式在PHP中:
$mycontent = preg_replace('{'.$words.'(?![^<>]*>)}i','otherwords',$mycontent);
它工作很好,但我需要排除标签内的文字,我该如何做?
许多感谢
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2012-08-01 15:21:50
永远不要用正则表达式解析html。改为使用[DomDocument](http://php.net/manual/en/class.domdocument.php)。 – Leri 2012-08-01 15:22:41
除了令人困惑的解析和匹配之外,愚蠢的链接是相关的。使用规定的正则表达式方法,只能通过高昂的工作才能完成。 (*你*不能)。否则建议使用HTML/DOM遍历前端。 – mario 2012-08-01 15:32:54