mnybud Posted August 28, 2006 Share Posted August 28, 2006 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 https://forums.phpfreaks.com/topic/18938-how-to-strip-urls-but-leave-anchor-text/ Share on other sites More sharing options...
Orio Posted August 28, 2006 Share Posted August 28, 2006 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. Link to comment https://forums.phpfreaks.com/topic/18938-how-to-strip-urls-but-leave-anchor-text/#findComment-81812 Share on other sites More sharing options...
DarkendSoul Posted August 28, 2006 Share Posted August 28, 2006 [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 https://forums.phpfreaks.com/topic/18938-how-to-strip-urls-but-leave-anchor-text/#findComment-81815 Share on other sites More sharing options...
mnybud Posted August 28, 2006 Author Share Posted August 28, 2006 PERFECT! Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/18938-how-to-strip-urls-but-leave-anchor-text/#findComment-81849 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.