Reputation: 1457
I have some text contain html tags, I would like to replace all links with other one, but I want to replace just local links, not they start with http:// example :
<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>
I try this preg_replace but not working :
$exclude = '<a href=\"http://.*?';
$pattern = '<a href=\".*?';
$content=preg_replace("~(($exclude)?($pattern))~i",'<a href="/action.php?url=$4',$content);
Thanks!
Upvotes: 2
Views: 1166
Reputation: 10176
What about something like this:
$content = preg_replace('#<a href="([^:]*)">#i', '<a href="/action.php?url=$1">', $content);
Upvotes: 2