Been busy with other things - I haven't tried out all of your options above - some of them created problems. I figured out this method which works fairly well:
PHP Code:
$text = "
Here is a text - www.ellehauge.net - it has some links with e.g. comma, www.one.com, in them.
Some links look like this: http://mail.google.com - mostly they end with a space or
carriage return www.unis.no
<br /> - but they may also end with a period: http://ellehauge.net. You may even put
the links in brackets (www.skred-svalbard.no) (http://one.com).
From time to time, links use a secure protocol like https://gmail.com - tricky, isn't it?
";
echo '<p>'.$text.'<br /> <br /></p>';
// anything which starts with "http" and has URL chars
$text = eregi_replace(
'http([-_./a-z0-9!&%#?+,\'=:;@~]+)',
'<a href="http\\1" rel="ext">http\\1</a>', $text);
// anything which starts with "www." and has URL chars
$text = eregi_replace(
'www.([-_./a-z0-9!&%#?+,\'=:;@~]+)',
'<a href="http://www.\\1" rel="ext">www.\\1</a>', $text);
// remove "," from the end of hrefs
$text=str_replace('," rel="ext">','" rel="ext">',$text);
// remove "." from the end of hrefs
$text=str_replace('." rel="ext">','" rel="ext">',$text);
echo '<p>'.$text.'</p>';
- except that I still get hyperlinks where the "," and "." still APPEAR within the link - although it has been removed from the link itself. I.e. technically it works - but it doesn't look great. Any ideas how to get the comma/period out of the text?
I might try out some of your solutions above if they proved to work?
NB: Ignore the <<rel="ext">> - it has something to do with some javascripting to avoid using the depricated "target:_blank" ...
Bookmarks