Converting a URL to a clickable hyperlink

With regular expressions, it is possible to transform any hyperlink URL of the form

http://URL (or ftp://URL) or beginning with www. :

$message = eregi_replace("((([ftp://])|(http(s?)://))((:alnum:|[-\%\.\?\=\#\_\:\&\/\~\+\@\,\;])*))","<a href = '\\0' target='_blank'>\\0</a>",$message);

$message = eregi_replace("(([^/])www\.|(^www\.))((:alnum:|[-\%\.\?\=\#\_\:\&\/\~\+\@\,\;])*)","\\2<a href = 'http://www.\\4' target='_blank'>www.\\4</a>",$message);
Published by jak58. Latest update on April 7, 2009 at 05:28 AM by jak58.
This document, titled "Converting a URL to a clickable hyperlink," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
Conditional Hyphenation HTML
Adjust Your Website to Fit All Resolutions