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? Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
mnybud Posted August 28, 2006 Author Share Posted August 28, 2006 PERFECT! Thanks a lot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.