How to filter bad words?

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"]);
Share

3 thoughts on “How to filter bad words?

  1. Pingback: 如果过滤“bad words”? - Final博客

Leave a Reply

Your email address will not be published. Required fields are marked *