sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Andrew DeFaria's Avatar

General linkify routine


Question posted by: Andrew DeFaria (Guest) on July 17th, 2005 12:47 PM
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?

0 Answers Posted
 
Not the answer you were looking for? Post your question . . .
196,820 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,820 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors