Forum Moderators: coopster
Problems is that when people type "something.something else" that's also turned into an url.
So what I'd like to do is change the below expression to only turn it into urls when you type either "www" in front (www.google.com) or when you use "http://" (http://google.com,http://www.google.com).
$text_s = preg_replace("/(?<=^¦\s)((https?¦ftps?):\/\/)?(([-_a-zA-Z0-9]+\.)+)([a-zA-Z0-9]{2,6})(\/[^\]\[\s]*)?(?=\s¦$)/e","'$1'!=''? '<a href=\"$1$3$5$6\" target=\"_blank\">$1$3$5$6</a>':'<a href=\"http://$3$5$6\" target=\"_blank\">$3$5$6</a>'",$text_s);
Thanks in advance =)
If you want the function to process query strings, such as:
[php.net...]
modify the function as follows:
function hyperlink(&$text)
{
// match protocol://address/path/
$text = ereg_replace("[a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%])*", "<a href=\"\\0\">\\0</a>", $text);
// match www.something
$text = ereg_replace("(^¦ )(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
}