Jump to content

How to Strip Urls but Leave Anchor Text?


mnybud

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?
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.