<?php
$text = "here is a link to www.google.com";
$text2 = "here is a link to http://www.stackoverflow.com";
$content = preg_replace('!((http://|www\.)+[a-z0-9_./?=&-]+)!i', '<a href="$1">$1</a> ', $text." ");
echo $content;
echo "\n";
$content = preg_replace('!((http://|www\.)+[a-z0-9_./?=&-]+)!i', '<a href="$1">$1</a> ', $text2." ");
echo $content;
?>