Having following code to turn an URL in a message into HTML links:
$message = preg_replace("#(http|https|ftp|ftps)://([.]?[&;%=a-zA-Z0-9_/?-])*#",
"<a href=\"away?to=\\0\" target=\"_blank\">\\0</a>", $message);
$message = preg_replace("#(^| |\n)(www([.]?[&;%=a-zA-Z0-9_/?-])*)#",
"\\1<a href=\"away?to=http://\\2\" target=\"_blank\">\\2</a>", $message);
It works very good with almost all links, except in following cases:
1) http://example.com/mediathek#/video/1976914/zoom:-World-Wide
Problem here is the #
and the :
within the link, because not the complete link is transformed.
2) If someone just writes "www" in a message
Example: <a href="http://www">www</a>
So the question is about if there is any way to fix these two cases in the code above?