php表单curse-word输入过滤器解决方案

时间:2011-07-01 14:19:49

标签: php validation input-filtering

我正在使用php和codeigniter框架构建一个Web应用程序,客户端的一个要求是在验证时实现“咒骂词”过滤器。有谁知道用PHP编写的任何预建解决​​方案?或者,一个详尽的诅咒词列表,我可以格式化成PHP语法数组并检查它们在用户输入中的存在?谢谢!

3 个答案:

答案 0 :(得分:7)

This should be able to get you started 的基本想法,但你必须填写自己的坏话。的 You can download a list of bad words here.

但是,我必须警告你,脏话过滤器有一些不可逾越的问题。英语语言过于灵活,无法阻止人们以多种不同方式拼写咒骂词。即使您可以阻止@$$h01e,也绝不会可靠地阻止αṡṡhølε,{{1}}可以很容易地阻止{{1}}。当每个单词和字母都有20多个潜在替代品时,你甚至无法开始过滤所有可能性。

另外,一旦人们意识到你有一个脏话过滤器,它可能会成为一个游戏,弄清楚如何阻止它,这可能导致比你开始时更多的咒骂! 如果人们想发誓,他们会找到一种方法。幸运的是,有很多网站已经处理过这个问题。你可以做的是让他们不想发誓,为他们提供最好的网站和内容体验,并提供一个简单的标记功能,以便用户可以通知你不可避免的案例。

Stackoverflow没有诅咒文字过滤器,你多久看一次咒骂?不要送电脑去做人的工作。 :d

答案 1 :(得分:1)

我绝对讨厌这存在,但它是:

http://www.noswearing.com/about.php

答案 2 :(得分:1)

这是我为客户制作的亵渎过滤器,如果这有助于任何人让我知道:D

    // function use cleanItUp($cmt:String,$wordlist:String,$character:string,$returnCount:boolean)
//$cmt 
//      Expects a string;
//           ex:'this is a lovely day to walk the dog'
//$wordlist
//      Expects a list of words to be replaced seporated by a verticle line '|'
//      default world list provided;
//             ex:'is|fun|good|dog'
//$character
//      Expects a single character to replace each character of the replaced word
//      default is an asterix '*'
//$returnCount
//      Expects true if you would only like to return the amount of words that were replaced;
//      default is set to false

// Usage Example
//      using default word list
//          cleanItUp('this is a lovely day to walk the dog');
//          returns 'this is a lovely day to walk the dog'
//      using custom wordlist
//          cleanItUp('this is a lovely day to walk the dog','is|day|dog');
//          returns 'this ** a lovely *** to walk the ***'
//      using custom wordlist and character
//          cleanItUp('this is a lovely day to walk the dog','is|day|dog','#');
//          returns 'this ## a lovely ### to walk the ###';
//      using custom wordlist and setting $returnCount to true
//          cleanItUp('this is a lovely day to walk the dog','is|day|dog','#',true);
//          returns 3;
function cleanItUp($cmt,$wordlist=null,$character="*",$returnCount=false)
{           
    if($wordlist==null)
    {
        $wordlist="nigga|nigger|niggers|sandnigger|sandniggers|sandniggas|sandnigga|honky|honkies|chink|chinks|gook|gooks|wetback|wetbacks|spick|spik|spicks|spiks|bitch|bitches|bitchy|bitching|cunt|cunts|twat|twats|fag|fags|faggot|faggots|faggit|faggits|ass|asses|asshole|assholes|shit|shits|shitty|shity|dick|dicks|pussy|pussies|pussys|fuck|fucks|fucker|fucka|fuckers|fuckas|fucking|fuckin|fucked|motherfucker|motherfuckers|motherfucking|motherfuckin|mothafucker|mothafucka|motherfucka";
    }
    $replace = 'preg_replace("/./","' .$character .'","\\1")';
    $comment = preg_replace("/\b($wordlist)\b/ie", $replace,$cmt,-1,$count);

    if($returnCount!=false)
    {
        return $count;
    }
    elseif($returnCount!=true)
    {
        return $comment;
    }
}