为了保证自己网站的纯洁性,作为服务端的一员我们有必要对用户的输入做过滤,
以下是我自己通过百度总结的自己的过滤的方法
key.txt是要过滤的敏感词的txt文件
public function FilterWorde($str){
$content = file_get_contents("../public/word/key.txt");
$arr = explode("|",$content);
for($i = 0;$i< count($arr);$i++){
if($arr[$i] == ""){
continue;
}
if(strpos($str,$arr[$i]) !== false){
$pos = strpos($str,$arr[$i]);
$str = substr_replace($str,"**",$pos,strlen($str));
return $str;
}
}
}
要用的客户可以根据自己的需求来改