PHP 表单诅咒词输入过滤器解决方案



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

这应该能够让你从基本想法开始,但你必须自己填满坏词。您可以在此处下载坏词列表。

但是,我必须警告您,脏话过滤器有一些无法克服的问题。英语太灵活了,无法阻止人们以许多不同的方式拼写脏话。即使你可以阻止@$$h01e,你也永远不会可靠地阻止αṡṡhølε,这可以很容易地由字符翻译器产生。当每个单词和字母可以有 20+ 个潜在的替代品时,您甚至无法开始过滤掉所有可能性。

此外,一旦人们意识到你有一个脏话过滤器,它可能会成为一个游戏来弄清楚如何阻止它,这可能会导致比你开始时更多的咒骂!如果人们想发誓,他们会想办法这样做。幸运的是,有很多网站已经处理了这个问题。您可以做的是通过为他们提供您的网站和内容的最佳体验,并提供简单的标志功能,以便用户可以通知您无法预防的情况,从而使他们不想发誓。

Stackoverflow没有诅咒词过滤器,你在这里多久看到一次咒骂?不要派计算机去做人类的工作。:D

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

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

这是我

为客户制作的亵渎过滤器,如果这有助于任何人让我知道: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;
    }
}

最新更新