paulbenjaminturner Posted February 14, 2007 Share Posted February 14, 2007 Hi, Apologies if this has already been addressed, but I've spent quite a while searching and can't seem to find an answer. I'm looking for a function to be used on my forum which will automatically locate a URL that a user has posted and convert it into an html link. Thanks very much, Paul Link to comment https://forums.phpfreaks.com/topic/38469-converting-posted-url-to-html-link/ Share on other sites More sharing options...
mbtaylor Posted February 14, 2007 Share Posted February 14, 2007 $url = $_POST['url']; print (create_url($url)); function create_url ($url) { if (!stristr ($url, "http://"))$url = "http://".$url; $httplink = "<a href='$url'>$url</a>"; return ($httplink); } Something like that? Link to comment https://forums.phpfreaks.com/topic/38469-converting-posted-url-to-html-link/#findComment-184549 Share on other sites More sharing options...
paulbenjaminturner Posted February 19, 2007 Author Share Posted February 19, 2007 Hi Thanks for your reply. That would work fine if I knew the entire URL, but I need a function that will locate it within a string that could contain hundreds of other words. Thanks, Paul Link to comment https://forums.phpfreaks.com/topic/38469-converting-posted-url-to-html-link/#findComment-188512 Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 Is the url located in a db or something? Link to comment https://forums.phpfreaks.com/topic/38469-converting-posted-url-to-html-link/#findComment-188518 Share on other sites More sharing options...
mbtaylor Posted February 19, 2007 Share Posted February 19, 2007 Then you need to use a regular expression using preg_replace. Look up url matching regular expressions. There might be more answers in the regular expressions forum. Link to comment https://forums.phpfreaks.com/topic/38469-converting-posted-url-to-html-link/#findComment-188529 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.