hi all,
my shortened function below simply takes a user input and links any URLs or email addresses appropriatly in HTML so when posted links work as seen on facebook etc
no matter what I do I always get the same basic problem that when two or more URLs are entered in a row (without spaces or joined with another character) all of the links get joined into one
i.e user submits:
that whole string would be one link instead of three?
I know someone must have the answer - interestingly on posting realised the same happens here (
thanks in advance
my shortened function below simply takes a user input and links any URLs or email addresses appropriatly in HTML so when posted links work as seen on facebook etc
Code:
/* Convert all URL matches to appropriate HTML links */
$message = preg_replace('#([\s|^])([URL unfurl="true"]www)#i',[/URL] '$1[URL unfurl="true"]http://$2',[/URL] $message);
$pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
$replacement = '<a href="$1" target="_blank">$1</a>';
$message = preg_replace($pattern, $replacement, $message);
/* Convert all E-mail matches to appropriate HTML links */
$pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
$pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
$replacement = '<a href="mailto:\\1">\\1</a>';
$message = preg_replace($pattern, $replacement, $message);
no matter what I do I always get the same basic problem that when two or more URLs are entered in a row (without spaces or joined with another character) all of the links get joined into one
i.e user submits:
that whole string would be one link instead of three?
I know someone must have the answer - interestingly on posting realised the same happens here (
thanks in advance