bpops Posted August 15, 2006 Share Posted August 15, 2006 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! ??? Quote Link to comment Share on other sites More sharing options...
bpops Posted August 15, 2006 Author Share Posted August 15, 2006 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? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 16, 2006 Share Posted August 16, 2006 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........ Quote Link to comment Share on other sites More sharing options...
bpops Posted August 16, 2006 Author Share Posted August 16, 2006 Thanks! I will have to read up a bit more on this preg_replace, but this is the solution I've been looking for! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.