A function to create links.
Posted: Thu Jun 05, 2008 4:23 pm
Currently I'm using this:
Unfortunately, it's not very good. It doesn't allow for http://'s to be linked without a www, and also, I can't use the function to auto-detect when someone posts a link (in mail, or the forums) which is simply not going to work.
So do any of you know one?
Code: Select all
function create_links($message)
{
$message = ereg_replace($message, "(^|[\n ])([\w]+?://[^ ,\"\"\s<]*)", "$1<a href=\"\"$2\"\">$2</a>");
$message = ereg_replace($message, "(^|[\n ])((www|ftp)\.[^ ,\"\"\s<]*)", "$1<a href=\"\"http://$2\"\">$2</a>");
$message = ereg_replace($message, "(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)", "$1<a href=\"\"mailto:$2@$3\"\">$2@$3</a>");
$message = right($message, len($message)-1);
return $message;
}
So do any of you know one?