its not perfect cause it consumes the whitespaces after the url and then you end up losing the space or worse the newline after a url, but it does the replacement. it shouldnt be too much work to fix that, but its late and im tired and my eyes are having trouble with that lol.
<?php
$text = <<<EOD
www.google.com/yeahh www.yahoo.com
http://www.msn.com/
https://www.search.com
EOD;
$reg = array("/\s(www\.(?:\S+))/i",
"/\s((?:f|ht)tps?:\/\/(?:\S+))/i");
$rep = array("<a href=\"http://\\1\">\\1</a>",
"<a href=\"\\1\">\\1</a>");
echo preg_replace($reg, $rep, " " . $text);
?>