阻止 PHP 中的粗俗/粗俗/淫秽术语

发布于 2024-10-16 08:45:52 字数 500 浏览 6 评论 0原文

我知道你可能会笑,但实际上这是大多数应用程序中的常见需求。许多接受客户/访客输入的应用程序可能需要过滤脏话或粗俗术语。

有时 PHP 会发生变化并添加新内容。例如,就在前几天我了解到 PHP5 中的 MultiCurl API。那么,无论如何,PHP 中是否有一个新的本机函数可以让我过滤字符串中最常见的基于英语的脏话,以及翻转一个布尔值来表示“字符串中有基于英语的脏话”?显然,它不需要完美,但要去掉一些垃圾,让我用 ### 替换它。

如果这还不是 PHP 的一部分,那么有人有一个函数可以让我使用它来隐藏咒语单词列表吗?例如,我希望这样我可以将课程删除到项目中,而不必担心另一个程序员会被冒犯。换句话说,这是一份经过适当编码的脏话列表——实际上并没有拼写出来。

现在,显然需要灵活一些,让“反驳”这样的词能够通过。

tl;dr: PHP5现在有原生功能可以过滤淫秽词语吗?如果没有,是否有人有一个类可以对脏话列表进行编码,这样就不会冒犯其他程序员?

I know you might laugh, but actually this is a common need in most apps. Many apps that take in customer/visitor input may need to filter cuss words or vulgar terms.

Sometimes PHP changes and new stuff gets added in. For instance, just the other day I learned about MultiCurl API in PHP5. So, anyway, is there a new native function in PHP that lets me filter most common English-based cuss words in a string, as well as flip a boolean to say, "string had English-based cuss words in it"? It doesn't need to be perfect, obviously, but cut out a good bit of garbage and let me replace it with ### for instance.

If that's not part of PHP yet, then does anyone have a function that I can use which cloaks the cuss word list? For instance, I want it such that I can drop the class in a project and not have to worry about another programmer getting offended. In other words, a decently encoded cuss word list -- not one actually spelled out.

Now, obviously it needs to be flexible and let words like "rebuttal" get through.

tl;dr: Does PHP5 now have a native function that can filter obscene words? And if not, does anyone have a class that encodes a cuss word list so that it doesn't offend other programmers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2024-10-23 08:45:52

我怀疑这对于 PHP 核心团队来说是一个高度优先的事情,因为这非常接近审查制度。审查制度是因为他们有一个“不适当”语言的“主”列表,应该对其进行过滤。

您可以相当简单地做到这一点。将要过滤掉的所有单词组成一个数组,当显示包含用户输入的页面时,对这些单词运行 preg_filter()

$bad_words = array('哔哔', '哔哔');
$subscribed_text = '废话......';

回声 preg_filter($bad_words, $replace, $subscribed_text);

注意:您将必须处理一些边缘情况,即好词中可能包含坏词(即“shitzu[原文如此]狗”)

编辑
对于好词里面有坏词的问题,您可以添加到正则表达式中,要求坏词的开头和结尾处有空格。如果你有很多提交的内容,那么与巨魔的斗争将是一场持续不断的战斗。

I doubt this is something that would be a high priority for the core PHP team since that treads dangerously close to censorship. Censorship in that they would have a 'master' list of 'inappropriate' language which should be filtered.

You can do this fairly simply. Make up an array of all the words you want filtered out and when a page is displayed that contains user input run a preg_filter() on the words.

$bad_words = array('bleeping', 'blooping');
$submitted_text = 'bleh blah....';

echo preg_filter($bad_words, $replace, $submitted_text);

Note: you will have to deal with the edge cases where a bad word might be inside of a good word (i.e.- 'shitzu[sic] dog')

EDIT
For the bad-words-inside-good-words issue, you can add to the regular expression to require space at the beginning and end of the bad word. If you have lots of submissions though, it's going to be a constant battle to keep up with the trolls.

单挑你×的.吻 2024-10-23 08:45:52
<?php
$badwords = "fuc";
$replacebad = "****"; 
$string = $_POST['something']; 
$filtered = str_ireplace($badwords, $replacebad, "$string");
echo $filtered;
?>

像这样的东西?
编辑:
抱歉我没有注意到 php5 部分..

<?php
$badwords = "fuc";
$replacebad = "****"; 
$string = $_POST['something']; 
$filtered = str_ireplace($badwords, $replacebad, "$string");
echo $filtered;
?>

something like this ?
Edit:
sorry I didn't noticed the php5 part ..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文