【发布时间】:2017-03-01 00:18:48
【问题描述】:
我有一个可以工作的内容过滤器,但它并没有像我想要的那样工作。 例如,如果我说“badword you i badword hat you”,则整个内容输出为“[CONTENT DELETED]”,但我希望它说“******* you i ******* hat you” "
<?php
function SecurePost($var) {
return trim($DBcon->real_escape_string($var));
}
function filter($string) {
$words = array("badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere", "badwordhere");
$new = array("****", "*****", "***", "*******", "****", "****", "*****", "******", "*****", "******", "*****", "***", "*******", "***", "****", "***", "*****", "*******", "****", "****", "*****", "****", "****", "****", "******");
$string1 = str_ireplace($words, $new, $string);
$findme = "***";
$pos = strpos($string1, $findme);
if ($pos !== false) {
$string1 = "[ Content Deleted ]";
return $string1;
}
else {
return $string1;
}
}
function SecureString($value) {
$value = mysql_real_escape_string(stripslashes(strip_tags($value)));
return $value;
}
?>
【问题讨论】:
-
这是一项不可能完成的任务,你可以捕捉到不好的词(使用很长的字典),但你无法捕捉到这些词的所有变体:
FuUuCk, @ 987654323@... 简而言之,尝试这样做只是浪费时间,并不能取代版主。新闻:我们现在是2017年,您可以毫无风险地使用所有mysql_功能。 -
我知道我不能阻止他们,那不是我的问题......
-
也许,但这是我的答案。