Vivid Lust Posted February 17, 2010 Share Posted February 17, 2010 If this was the text: text text http://www.phpfreaks.com text How could php find the url, any url, and then make it: text text <a href="http://www.phpfreaks.com ">http://www.phpfreaks.com</a> text Thanks all!! Quote Link to comment Share on other sites More sharing options...
premiso Posted February 17, 2010 Share Posted February 17, 2010 $str= preg_replace("/([^A-z0-9])(http|ftp|https)([\:\/\/])([^\\s]+)/","<a href=\"$2$3$4\">$2$3$4</a>",$str); From http://codingforums.com/showthread.php?t=181757 Also was discussed previously in the regex forum at http://www.phpfreaks.com/forums/index.php/topic,287639.0.html. Please review the proper sections and search for your answer before posting, as chances are it has been answered many times before. Quote Link to comment Share on other sites More sharing options...
maddali Posted February 17, 2010 Share Posted February 17, 2010 It's not working in my case... I've a function that takes some text in the field an converts that into url if it's present....however,it displays the whole text and url as an hyperlink...and when clicked on text it displays page doesn't exist,which it is supposed to display... function make_url_link($url) { if(empty($url)) { return; } $url= preg_replace("/([^A-z0-9])(http|ftp|https)([\:\/\/])([^\\s]+)/","<a href=\"$2$3$4\">$2$3$4</a>",$url); return '<a href="'.$url.'">'.$url.'</a>'; } Any suggestions??? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 17, 2010 Share Posted February 17, 2010 preg_replace('%\b(http|https)://[-A-Z0-9+&@#/?=~_|!:,.;]*[-A-Z0-9+&@#/=~_|]%i', '<a href="\0">\0</a>', $text); HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 18, 2010 Author Share Posted February 18, 2010 How could I do the above in javascript? Thanks!!"! Quote Link to comment Share on other sites More sharing options...
premiso Posted February 18, 2010 Share Posted February 18, 2010 How could I do the above in javascript? Thanks!!"! Do your own research? Post a new question in the Javascript Forum? All of the above? 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.