Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of PHP profanity filter [duplicate]

Tags:

php

iphone

Possible Duplicate:
How do you implement a good profanity filter?

I have an iPhone app that passes a string through a URL to my php script, which then inserts to my database. I'd like to write some php code that reads $body for any pre-defined profanity.

Right now, I only have the following code, but it only looks for exact matches, not if $body contains, then.. type of a sequence. Also, I need it to replace the swear with a blank " ", removing the word all together.

if($body == "swear word") 
    return;
like image 625
BigMike Avatar asked Jun 12 '26 18:06

BigMike


1 Answers

$swears = array("shoot", "darn", "heck");

foreach ($swears as $bad_word)
    $body = str_replace($bad_word, " ", $body);

This will work as a quick-and-dirty solution, although it does have the Scunthorpe Problem (e.g. "heckler" will get transformed to "ler" if "heck" is on your profanity list).

like image 156
eliah Avatar answered Jun 14 '26 08:06

eliah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!