Badword filter in PHP?

Posted by morpheous on Stack Overflow See other posts from Stack Overflow or by morpheous
Published on 2010-05-19T04:45:34Z Indexed on 2010/05/19 4:50 UTC
Read the original article Hit count: 199

Filed under:

I am writing a badword filter in PHP.

I have a list of badwords in an array and the method cleanse_text() is written like this:

public static function cleanse_text($originalstring){
   if (!self::$is_sorted) self::doSort();
   return str_ireplace(self::$badwords, '****', $originalstring);
}

This works trivially, for exact matches, but I wanted to also censor words that have been disguised like 'ab*d' where 'abcd' is a bad word. This is proving to be a bit more difficult.

Here are my questions:

  1. Is a badword filter worth bothering with (it is a site for professionals so a certain minimum decorum is required - I would have thought)

  2. Is it worth the hustle of trying to capture obvious work arounds like 'f*ck' - or should I not attempt to filter those out.

  3. Is there a better way of writing the cleanse_text() method above?

© Stack Overflow or respective owner

Related posts about php