General linkify routine

From: Andrew DeFaria (Andrew_at_DeFaria.com)
Date: 02/28/05


Date: Mon, 28 Feb 2005 19:35:35 GMT


Somebody asked me to make links of strings like http://somewhere.com in
my PHP page. Here's my first stab at it:

function linkify ($text) {
  return preg_replace ("/(http:\/\/.*\b)/",
               "<a href=\"$1\">$1</a>",
         preg_replace ("/(ftp:\/\/.*\b)/",
               "<a href=\"$1\">$1</a>",
               $text));
} // linkify

However this fails in some cases (like when you have
http://somewhere.com, with a "," in a natural sentence). Plus the above
only handles http and ftp style builds. Rather than reinventing the
wheel as it were I was wondering if anybody had a better, more
generalized routine...

-- 
Why are they called stairs inside but steps outside?