I use this function to make links clickable:
function clickable($text) {
$text = preg_replace("/(https?|ftps?|mailto):\/\/([-\w\p{L}\.]+)+(:\d+)?(\/([\w\p{L}#-;+-\/_\.]*(\?\S+)?)?)?/u", '<a target="_blank" href="$0">$0</a>', $text);
return $text;
}
It works fine but there is one little problem. If the $text variable contains a string like this:
some text
i.e. link, line break(s) and some text, I get incorrect result. Instead of this:
<a target="_blank" href="http://example.com">http://example.com</a>
it becomes:
<a target="_blank" href="http://example.com<br">http://example.com</a>
/>
some text
Here is how I display text on my site:
<?php echo clickable(nl2br($db['content'])); ?>
nl2br function converts all line breaks into html <br /> tags but this function thinks it should keep this tag in url...
Hope I'm clear :)
Any ideas?
[#-;+-\\]- is this intentional? For one,[#-;]contains[+-\\], which is weird.