php坏字内容过滤器
我有一个可以工作的内容过滤器,它不能像我希望的那样工作。 例如,如果我说“badword you i badword hate you”,整个内容输出为“[CONTENT DELETED]”,但我希望它说“******you i*********hate you”php坏字内容过滤器,php,arrays,mysqli,Php,Arrays,Mysqli,我有一个可以工作的内容过滤器,它不能像我希望的那样工作。 例如,如果我说“badword you i badword hate you”,整个内容输出为“[CONTENT DELETED]”,但我希望它说“******you i*********hate you” 代码中几乎没有bug。请检查以下工作示例: <?php $str = "Kiss my badwordhere"; echo filter($str) . "\n"; $str = "badwordhere anywhereb
代码中几乎没有bug。请检查以下工作示例:
<?php
$str = "Kiss my badwordhere";
echo filter($str) . "\n";
$str = "badwordhere anywherebadword";
echo filter($str) . "\n";
function filter($string) {
$words = array("badwordhere", "anywherebadword");
$new = array("****", "*******");
$string1 = str_ireplace($words, $new, $string);
$left = preg_replace("/[\* ]+/", "", $string1);
if (strlen($left) == 0) {
$string1 = "[ Content Deleted ]";
return $string1;
}
else {
return $string1;
}
}
?>
代码中几乎没有bug。请检查以下工作示例:
<?php
$str = "Kiss my badwordhere";
echo filter($str) . "\n";
$str = "badwordhere anywherebadword";
echo filter($str) . "\n";
function filter($string) {
$words = array("badwordhere", "anywherebadword");
$new = array("****", "*******");
$string1 = str_ireplace($words, $new, $string);
$left = preg_replace("/[\* ]+/", "", $string1);
if (strlen($left) == 0) {
$string1 = "[ Content Deleted ]";
return $string1;
}
else {
return $string1;
}
}
?>
这是一项不可能完成的任务,你可以用一本很长的字典找出不好的单词,但你不能找出这些单词的所有变体:
FuUuCk
,b1owJ0b
。。。简言之,试图这样做只是浪费时间,并不能取代主持人。新闻:我们现在是2017年,你可以毫无风险地停止使用所有的mysql\uuuu
函数。我知道我不能全部停止它们,这不是我的问题……也许,但这是我的答案。这是一项不可能的任务,你可以抓住不好的单词(用很长的字典),但你不能抓住这些单词的所有变体:FuUuCk
,b1owJ0b
。。。简言之,试图这样做只是浪费时间,并不能取代主持人。新闻:我们现在是2017年,你可以毫无风险地停止使用所有的mysql\uu
函数。我知道我不能全部停止它们,这不是我的问题……也许,但这是我的答案。
Kiss my ****
[ Content Deleted ]