我们中的许多人都需要处理用户输入、搜索查询以及输入文本可能包含亵渎或不受欢迎的语言的情况。通常情况下,这需要过滤掉。

在哪里可以找到各种语言和方言的粗口?

源代码中是否有包含好的列表的api ?或者可能是一个API,用一些参数简单地说“是的,这是干净的”或“不,这是脏的”?

有什么好方法可以捕捉那些试图欺骗系统的人,比如$$、azz或a55?

如果您为PHP提供了解决方案,则会有加分。:)

编辑:回答简单地说,避免程序问题:

我认为,当用户可以使用公共图像搜索来查找添加到敏感社区池的图片时,这种过滤器是有一席之地的。如果他们可以搜索“阴茎”,那么他们可能会得到很多照片,是的。如果我们不想要照片,那么阻止这个词作为搜索词是一个很好的把关者,尽管不可否认这不是一个万无一失的方法。真正的问题是首先获得单词列表。

我指的是一种方法来判断单个令牌是否脏,然后简单地禁止它。我不会费心去阻止那种完全滑稽的“长脖子长颈鹿”的说法。你在那里什么也做不了。:)


当前回答

不喜欢。这只会导致问题。我个人有一次使用脏话过滤器的经历是,有一次我在IRC频道上提到我“要去汉考克的桥上呆几个小时”或类似的事情,就被踢/禁止进入。

其他回答

如果你能做一些像Digg/Stackoverflow那样的事情,让用户可以投票/标记淫秽内容……这样做。

然后你所需要做的就是审查那些“淘气”的用户,如果他们违反了规则,就把他们屏蔽掉。

不喜欢。这只会导致问题。我个人有一次使用脏话过滤器的经历是,有一次我在IRC频道上提到我“要去汉考克的桥上呆几个小时”或类似的事情,就被踢/禁止进入。

一旦你有了一个好的MYSQL表,里面有一些你想要过滤的坏单词(我从这个线程中的一个链接开始),你可以这样做:

$errors = array();  //Initialize error array (I use this with all my PHP form validations)

$SCREENNAME = mysql_real_escape_string($_POST['SCREENNAME']); //Escape the input data to prevent SQL injection when you query the profanity table.

$ProfanityCheckString = strtoupper($SCREENNAME); //Make the input string uppercase (so that 'BaDwOrD' is the same as 'BADWORD').  All your values in the profanity table will need to be UPPERCASE for this to work.

$ProfanityCheckString = preg_replace('/[_-]/','',$ProfanityCheckString); //I allow alphanumeric, underscores, and dashes...nothing else (I control this with PHP form validation).  Pull out non-alphanumeric characters so 'B-A-D-W-O-R-D' shows up as 'BADWORD'.

$ProfanityCheckString = preg_replace('/1/','I',$ProfanityCheckString); //Replace common numeric representations of letters so '84DW0RD' shows up as 'BADWORD'.

$ProfanityCheckString = preg_replace('/3/','E',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/4/','A',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/5/','S',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/6/','G',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/7/','T',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/8/','B',$ProfanityCheckString);

$ProfanityCheckString = preg_replace('/0/','O',$ProfanityCheckString); //Replace ZERO's with O's (Capital letter o's).

$ProfanityCheckString = preg_replace('/Z/','S',$ProfanityCheckString); //Replace Z's with S's, another common substitution.  Make sure you replace Z's with S's in your profanity database for this to work properly.  Same with all the numbers too--having S3X7 in your database won't work, since this code would render that string as 'SEXY'.  The profanity table should have the "rendered" version of the bad words.

$CheckProfanity = mysql_query("SELECT * FROM DATABASE.TABLE p WHERE p.WORD = '".$ProfanityCheckString."'");
if(mysql_num_rows($CheckProfanity) > 0) {$errors[] = 'Please select another Screen Name.';} //Check your profanity table for the scrubbed input.  You could get real crazy using LIKE and wildcards, but I only want a simple profanity filter.

if (count($errors) > 0) {foreach($errors as $error) {$errorString .= "<span class='PHPError'>$error</span><br /><br />";} echo $errorString;} //Echo any PHP errors that come out of the validation, including any profanity flagging.


//You can also use these lines to troubleshoot.
//echo $ProfanityCheckString;
//echo "<br />";
//echo mysql_error();
//echo "<br />";

我确信有一种更有效的方法来完成所有这些替换,但我不够聪明,无法找到它(尽管效率不高,但这似乎还可以)。

我认为你应该允许用户注册,并根据需要使用人工过滤和添加到你的亵渎表。尽管这一切都取决于一个假阳性(好的词被标记为坏)和一个假阴性(坏词通过)的成本。这将最终决定您在过滤策略中是积极还是保守。

如果您想使用通配符,我也会非常小心,因为它们有时会比您想要的更麻烦。

我用12种语言背诵了2200个坏词:恩,ar, cs, da, de, eo, es, fa, fi, fr, hi, hu, ja, ko, nl, pl, pl, ru, tlh, zh。

MySQL转储,JSON, XML或CSV选项可用。

https://github.com/turalus/openDB

我建议你执行这个SQL到你的数据库,并检查每次当用户输入一些东西。

淫秽过滤器:坏主意,还是令人难以置信的坏主意?

此外,我们不能忘记Toontown的SpeedChat的不被人知的历史,在那里,即使使用“安全词白名单”,也会导致一个14岁的孩子迅速绕过它: “我想把我的长脖子长颈鹿插到你毛茸茸的白兔子身上。”

底线:最终,对于您实现的任何系统,绝对没有什么可以替代人工评审(无论是同行评审还是其他评审)。你可以随意使用一个基本的工具来消除这种恶意攻击,但对于那些顽固的恶意攻击者,你绝对必须使用一种非基于算法的方法。

一个消除匿名并引入问责制的系统(Stack Overflow在这方面做得很好)也很有帮助,特别是为了帮助对抗约翰·加布里埃尔的G.I.F.T.

你还问你从哪里可以得到亵渎列表来开始你的学习——一个开源项目是Dansguardian——看看他们默认的亵渎列表的源代码。还有一个额外的第三方短语列表,你可以为代理下载,这可能是一个有用的收集点。

编辑:谢谢你对你想要做的事情的澄清。在这种情况下,如果你只是想做一个简单的单词过滤器,有两种方法可以做到。一种方法是创建一个单独的长regexp,其中包含您想要审查的所有禁用短语,并使用它进行regex查找/替换。像这样的正则表达式:

$filterRegex = "(boogers|snot|poop|shucks|argh)"

并使用preg_match()在输入字符串上运行它来批量测试命中,

或preg_replace()来清空它们。

您还可以使用数组加载这些函数,而不是单个的长正则表达式,对于长单词列表,它可能更易于管理。有关如何灵活使用数组的一些好例子,请参阅preg_replace()。

有关其他PHP编程示例,请参阅本页,其中有一个比较高级的用于单词过滤的泛型类,它从经过审查的单词中删除了中间的字母,以及前面的Stack Overflow问题,其中也有一个PHP示例(其中主要有价值的部分是基于sql的过滤单词方法——如果您发现它不必要,可以省去let -speak补偿器)。

你还补充说:“真正的问题是首先获得单词列表。”——除了之前的一些丹斯格尔链接,你可能会发现这个458个单词的。zip很有用。