【发布时间】:2018-03-12 05:24:54
【问题描述】:
我需要从文本中删除 <a href,除非 href 中的域/url 包含 example.com
我找到了这个正则表达式,但它现在替换了所有 urls (.*?) ,任何想法如何使它替换所有hrefs except如果url包含example.com
preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $_POST['desc']);
这是替换应该如何工作的示例
<a href="http://example.com/test">test1</a> ==> Should not be replaced (targeted)
<a href="http://google.com/test">test2</a> ==> test2
【问题讨论】:
标签: php url preg-replace href