Connecting Tech Pros Worldwide Help | Site Map

General linkify routine

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 11:47 AM
Andrew DeFaria
Guest
 
Posts: n/a
Default General linkify routine

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?


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

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 220,662 network members.