我有一個內容過濾器可以工作,但它不會像我想要的那樣工作。例如,如果我說「壞字你是我的壞話恨你」,整個事情輸出爲「[內容刪除]」,但我希望它說「*******你,我*******恨你「php壞詞內容過濾器
<?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','b1owJ0b' ...總之,嘗試這樣做只是浪費時間,並不能取代主持人。新聞:我們現在在2017年,您可以無風險地停止使用所有'mysql_'函數。 –
我知道我不能阻止他們,這不是我的問題.... – noynac
也許,但這是我的答案。 –