如何解析HTML/XML并从中提取信息?
我需要以不区分大小写的方式查找和替换所有文本匹配项,除非文本位于锚标记内 - 例如:
<p>Match this text and replace it</p>
<p>Don't <a href="/">match this text</a></p>
<p>We still need to match this text and replace it</p>
Run Code Online (Sandbox Code Playgroud)
搜索"匹配此文本"只会替换第一个实例和最后一个实例.
[编辑]根据戈登的评论,在这个例子中可能更喜欢使用DOMDocument.我对DOMDocument扩展并不熟悉,并且非常感谢这个功能的一些基本示例.
php ×2
domdocument ×1
html-parsing ×1
parsing ×1
preg-replace ×1
regex ×1
xml ×1
xml-parsing ×1
xpath ×1