if($_POST)
{
//获取文件内容转为数组两种方法:
/*
$fcon = file_get_contents("./filter.txt");
$filter_word = explode("\n",$fcon);
*/
$filter_word = file("./filter.txt");
//$filter_word = array("test1","test2","test3","test4");
$str = $_POST["mess"];
for($i=0;$i
{
if(preg_match("/".(trim($filter_word[$i]))."/i",$str))
{
echo "<script>alert('您输入的内容含非法内容,请重输!');</script>";
echo "返回";
exit;
}
}
echo "您输入的内容是:".$str;
}
?>
测试过滤是否生效:
摘自:adamboy的博客