Jump to content


Photo

How to Strip Urls but Leave Anchor Text?


  • Please log in to reply
3 replies to this topic

#1 mnybud

mnybud
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 28 August 2006 - 08:19 PM

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?

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 28 August 2006 - 08:35 PM

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.
Think you're smarty?

(Gone until 20 to November)

#3 DarkendSoul

DarkendSoul
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 28 August 2006 - 08:41 PM

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?


Basicly right so far

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

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
<?
$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'
?>


#4 mnybud

mnybud
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 28 August 2006 - 09:56 PM

PERFECT!

Thanks a lot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users