You can use this simple function to filter bad words.
Please see attachment for mysql table of frequently used 458 bad words. http://www.phpmind.com/codedemo/php-bad-word-filter/bad_word.txt.zip
You can add more word easily as you know more!!
function bad_wordcensor($txt)
{
$q = mysql_query("SELECT bad_word, replacement FROM bad_words");
while ($row_bad = mysql_fetch_array($q))
{
$txt = str_ireplace($row_bad['bad_word'], $row_bad['replacement'], $txt);
}
return $txt;
}
echo bad_wordcensor($_POST["comments"]);
Your function is not to filter,but to replace.
Use function strtr instead.
Pingback: 如果过滤“bad words”? - Final博客