Jump to content

Filtering profanity (and other words)


bpops

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! ???
Link to comment
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?
Link to comment
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........
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.