一个简单的PHP内容过滤实例
<?php
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<count($filter_word);$i++)
{
if(preg_match("/".(trim($filter_word[$i]))."/i",$str))
{
echo "<script>alert('您输入的内容含非法内容,请重输!');</script>";
echo "<a href='index.php'>返回</a>";
exit;
}
}
echo "您输入的内容是:".$str;
}
?>
<h2>测试过滤是否生效:</h2>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><textarea name="mess" cols="40" rows="4"></textarea></p>
<p><input type="submit" name="sub" value="send"></p>
</form>
摘自:adamboy的博客
补充:Web开发 , php ,