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
https://forums.phpfreaks.com/topic/17658-filtering-profanity-and-other-words/
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........

Archived

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

×
×
  • 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.