Not exactly what you're looking for but may be this help:
Replace xxx
with yyy
if and only if xxx
is surrounded by spaces or if it is at the start or end of the string.
<?
$name = "xxx";
$text = "xxx my name is xxx en my website xxx is http://xxx.something.com xxx";
$text = preg_replace("%(?<=^| )".$name."(?= |$)%i", "yyy", $text);
echo $text."\n";
//yyy my name is yyy en my website yyy is http://xxx.something.com yyy
?>
It would have been easier if PHP supported variable length look behind assertions; because then we could have used a more accurate (?<!http://[^ ]+)\bxxx\b