开发者

Implementation of PHP profanity filter [duplicate]

开发者 https://www.devze.com 2023-01-16 12:32 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How do you implement a good profanity filter?
This question already has answers here: Closed 12 years ago.

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 t开发者_JAVA技巧he 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;


$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).

0

精彩评论

暂无评论...
验证码 换一张
取 消