It doesn't need to be a regular expression. I try to avoid them for simple string functions.
$words = explode(" ", $input_str);
$count = count($words);
for($x = 0; $x < $count; $x++)
{
if(strpos($words[$x], "www."))
{
$words[$x] = "<a href='".$words[$x]."'>".$words[$x]."</a>";
}
}
$output_str = implode(" ", $words);
I chose strpos() here because it is relatively fast compared to many other string functions. Also note, I added the braces for readability but none are required.