How to convert URLs to LINKs?

posted by softweb on 2009-06-29 16:18:48
Hello,
How to convert URLs to LINKs in php?
dail avatar
dail
12
 
    function url_to_link($s){
        $find = '((?:https?://|ftp://|www\.)[\w.-]+[^\s<>]+)';
        $link = "<a href=\"$0\" rel=\"nofollow\" target=\"_blank\">$0</a>";
        return preg_replace($find, $link, $s);
    }
 
Is not complete, but should work.
It converts these urls in links:
www.urltolink.ext
http://www.urltolink.ext
http://urltolink.ext
http://sub.urltolink.ext
49 answers - 0 questions
+ 1  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)