this function creates links from a string, but the problem is, if i already have a link, it doesn’t work e.g: ‘i am a link ‘, but it works with ‘i am a link http://www.google.com‘. any idea?
function checkStringForLinks($string)
{
/*** make sure there is an http:// on all URLs ***/
//$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
/*** make all URLs links ***/
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</A>",$string);
/*** make all emails hot links ***/
//$string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$string);
return $string;
}
ooops, wrongly types. what i meant is: i dont want it to touch \anchor\link\anchor\ instead, only links that are not formed
To make it right, it’s not so simple, there is already free solutions for that. Like this simple class linkify.