【发布时间】:2015-07-29 00:29:33
【问题描述】:
你好,我有以下标签:
$content ='<a href="http://website.com/" />
<a href="/link1" />
<a href="https://website.com" />
<a href="link1" />';
这个代码:
preg_replace('~href=(\'|"|)(.*?)(\'|"|)(?<!\/|http:\/\/|https:\/\/)~i', 'href=$1http://website2.com/$2$3', $content);
我想使用上面的代码替换不以 http 或 https 或斜杠开头的 href 标签。
提前致谢。
【问题讨论】:
-
我已经完成了 80% 的工作,而我的脚本仅使用正则表达式
-
所以,如果你能帮我用正则表达式做这件事,我将不胜感激
-
我会处理一些事情,在你的正则表达式中
$1假设是什么? -
$1 是为了 (\'|"|) 不是吗?
标签: php regex preg-replace