You'll want to use a case insensitive profanity filter, otherwise it will be stupid easy to break. So use regular expresions instead of str_replace. I hook mine into a db so words can be added i.e. the first time someone put in merde I would add it then it wouldn't get by anymore.
something like this
<?php
//build the list of bad words
$sql = "SELECT * FROM lang_filt";
$query = mysql_query($sql);
$badwords = array();
while(($row = mysql_fetch_object($query)) !== FALSE)
$badwords[$row->word] = $row->replace;
function filter($string,$words) {
foreach($words as $word => $replace) {
//replace instances of $word with a space after them
$string = eregi_replace($word . ' ',$replace,$string);
//replace instances of $word with a space before them
$string = eregi_replace(' ' . $word,$replace,$string);
} //end foreach
return $string;
} //end filter
?>
If you had the word ass replaced with but in your database then the following is what would happen to different strings.
You're an ass. -> You're an but
Suck my asshole. -> Suck my buthole
Ass -> but
aSs -> but
asS -> but
ASs -> but
aSS -> but
AsS -> but
Please asses my program as soon as possible. -> Please butes my program as soon as possible.
As you can see from the last example there is a weakness in this filetering scheme. But I can't remember off the top of my head how I fixed it. I think I make a list of accepted words, then did some sort of reversible suffling on the accepted words prior to removing the bad words then I unshuffled the accepted words.