I've created a function that automatically detects links. It works quite fine, except when a HTML tag begins just after a link (without space).
Example :
http://www.google.com is cool
becomes
<a href="http://www.google.com" target="_blank">www.google.com</a> is cool
but
http://www.google.com<br />is cool
(without space after http:// in real) becomes
<a href="http://www.google.com<br /" target="_blank">www.google.com<br /</a> is cool
My regular expression doesn't stop at first <, though < is not allowed...
How can I fix that ? Or how can I exclude < efficiently ?
Here's my function :
function detect_linkg($str){
return preg_replace('#(https?://)([\w\d.&:\#@%/;$~_?\+-=]*)#','<a href="$1$2" target="_blank">$2</a>',$str);
}
Thanks for your help !