Jump to content


Photo

Filtering profanity (and other words)


  • Please log in to reply
3 replies to this topic

#1 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 15 August 2006 - 06:43 PM

In a user-driven site, I'm attempting to filter certain profanity. The way I do this currently is by having an array of words:
$bad_words = array("XXXX","XXXX","XXXX");
then for an input message, I do a check, something like:
if (strtolower($message) != str_replace($bad_words, '', strtolower($message))){
  echo "Profanity found.";
}

The problem that I'm having is that people are using leet (1337) speak to use these words.. for example:
i's become !'s, o's become 0's (zero), s's become 5's, t's become 7's, etc. etc.

So if I wanted to filter the word "sit", I'd have to filter: sit, s!t, si7, 5it, s!7, 5!7, etc. etc. (all the combinations)

Anyone know of an easy way of doing this? Or does anyone know how others typically filter certain words? Or is there no easy way around it?
Thanks! ???

#2 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 15 August 2006 - 08:32 PM

One of my friends recommended I just look for numbers and anytime a number is sitting right next to an alphabetic character (e.g. 5h..), to just throw out an error.
While this will get rid of most leet speak, does anyone have another solution?

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 16 August 2006 - 12:23 AM

you can just do a preg_replace on the string.....

look for patterns (or regular expressions) like so....

$lookfor = array(
'/(s|5)hit/',
'/(ph|f)uck/',
'/a(s|5){2}/'
);

$message = preg_replace($lookfor, '****', $message);

still requires a bit of vigilance BUT if you keep at it for a while you have a killer profanity filter........
follow me on twitter @PHPsycho

#4 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 16 August 2006 - 06:49 PM

Thanks! I will have to read up a bit more on this preg_replace, but this is the solution I've been looking for!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users