【发布时间】:2012-08-31 04:32:18
【问题描述】:
今天早些时候,我问了一个关于使用正则表达式解决方案来用 return fo 某个函数替换 html 中所有链接的 hrefs 的问题..
然后我删除了它,因为我似乎可以使用 DomDocument 解决它,但事实证明,我不能......
看到我的 html 有很多错误的 html 语法、html5 代码等等等。所以 loadHTML 和 loadXML 都不起作用..
如果有人可以使用正则表达式提供解决方案来查找 href 并使用调用所有函数进行替换..我尝试过 preg_replace 和 preg_replace_callback,但我无法理解 $1、$2..整个概念。 . 我搜索了所有类似的问题,但他们都有 DomDocumenet 的答案,我无法使用..
旧的类似问题: Grabbing the href attribute of an A element
Find all hrefs in page and replace with link maintaining previous link - PHP
但我需要正则表达式解决方案
【问题讨论】:
标签: php html regex preg-replace preg-replace-callback