Jump to content

Archived

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

mnybud

How to Strip Urls but Leave Anchor Text?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
What dont you use:
$anchor=strstr($url,"#");
Since you wont find a "#" in another place :)
The result will be the anchor's name with a leading "#". For example "#anchor".
Then you can remove the anchor easiely.

Orio.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites

×

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.