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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. 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.