Jump to content

How to Strip Urls but Leave Anchor Text?


mnybud

Recommended Posts

[quote author=mnybud link=topic=105982.msg423545#msg423545 date=1156796342]
Hi I am trying to remove hyperlinks from some of my pages but leave the anchor text.
This is what I have so far, which will remove all the urls but it does not leave the anchor text.

if(!$edit_link) $article = preg_replace("/<a.*?href=.*?>(.*?)<\/a>/mi","",$article);

any help?
[/quote]

Basicly right so far

[code=php:0]
<?
if(!$edit_link) $article = preg_replace("/<a.*?href=(.*?)>(.*?)<\/a>/mi","\\2",$article);
?>
[/code]

I also added brackets around where the url would be... so if you wish to retreave that you could use


** still needs work x.x
[code=php:0]
<?
$article = '<a href="http://www.com.com">text</a>';
$url = preg_replace("/<a.*?href=[\"'](.*?)[\"'].*?>(.*?)<\/a>/mi","\\1",$article);

echo $url;
// Would output 'http://www.com.com'
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.