Page 1 of 1

A function to create links.

Posted: Thu Jun 05, 2008 4:23 pm
by Mightywayne
Currently I'm using this:

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;
}
 
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?

Re: A function to create links.

Posted: Fri Jun 06, 2008 1:05 am
by RobertGonzalez
What criteria are you trying to match to actually create a link?