我有一些包含html标记的文本,我想用其他链接替换所有链接,但我只想替换本地链接,而不是以http开头://示例:
<a href="local_link">test link</a>
==> <a href="local_link_to_be_replace?url=local_link">test link</a>
<a href="http://www.youtube.com">Video</a>
==> <a href="http://www.youtube.com">Video</a>
我尝试了这个preg_replace,但不起作用:
$exclude = '<a href='"http://.*?';
$pattern = '<a href='".*?';
$content=preg_replace("~(($exclude)?($pattern))~i",'<a href="/action.php?url=$4',$content);
谢谢!
这样的东西怎么样:
$content = preg_replace('#<a href="([^:]*)">#i', '<a href="/action.php?url=$1">', $content);