Better solution would be having the bad words in a TXT file which the script checks whether the word is in that file.
badwords.txt
BadWord1
BadWord2
BadWord3
BadWord4
BadWord5
badwords.php
<?
$text = 'very BadWord1 ugly words which are so much BadWord2 BadWord3 that its so BadWord4';
$file = file('badwords.txt');
for($i = 0; $i < count($file); $i++)
{
$bdwrd1[] = substr($file[$i],0,-1);
$bdwrd2[] = substr(str_repeat('*',strlen($file[$i])),0,-1);
}
$text = str_replace($bdwrd1,$bdwrd2,$text);
echo $text;
?>