Code:
$text=
"test 1: <a href=\"http://www.animeviews.com/article.php?ID=59\">http://www.animeviews.com/article.php?ID=59</a>. word.
<br>test 2: www.animeviews.com/article.php?ID=59. word.
<br>test 3: http://www.animeviews.com/article.php?ID=59. word.
<br>test 4: <a href=\"http://www.animeviews.com\">test 4</a>. word.
<br>test 5: <a href=\"www.animeviews.com\">www.animeviews.com</a> word.
<br>test 6: http://en.wikipedia.org/wiki/Portable_Network_Graphics word.";
Code:
<?php
$text = preg_replace('/(?<!http:\/\/|https:\/\/|\"|=|\'|\'>|\">)(www\..*?)(\s|\Z|\.\Z|\.\s|\<|\>|,)/i',"<a href=\"http://$1\">$1</a>$2",$text);
$text = preg_replace('/(?<!\"|=|\'|\'>|\">|site:)(https?:\/\/(www){0,1}.*?)(\s|\Z|\.\Z|\.\s|\<|\>|,)/i',"<a href=\"$1\">$1</a>$3",$text);
echo "$text";
?>
I have a small collection of PCRE. The one above is what I use for what you are describing. It has served me very well. Test 5, listed above is broken, but this is by design. It is not designed to fix broken hyperlinks, only to correctly hyperlink web addresses.
Bookmarks