Jump to content

Archived

This topic is now archived and is closed to further replies.

bpops

Filtering profanity (and other words)

Recommended Posts

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:
[code=php:0]$bad_words = array("XXXX","XXXX","XXXX");[/code]
then for an input message, I do a check, something like:
[code=php:0]
if (strtolower($message) != str_replace($bad_words, '', strtolower($message))){
  echo "Profanity found.";
}
[/code]

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! ???

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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........

Share this post


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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.