I want to have a function which gets a text as the input and gives back the text with URLs made to HTML links as the output.
My draft is as follows:
function autoLink($text) {
return preg_replace('/https?:\/\/[\S]+/i', '<a href="\0">\0</a>', $text);
}
But this doesn't work properly.
For the input text which contains ...
http://www.google.de/
... I get the following output:
<a href="http://www.google.de/<br">http://www.google.de/<br</a> />
Why does it include the line breaks? How could I limit it to the real URL?
Thanks in advance!