if($_POST)
{
//Two ways to get the file content and convert it into an array:
/*
$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('The content you entered contains illegal content, please re-enter!');</script>";
echo "return";
exit;
}
}
echo "The content you entered is:".$str;
}
?>
Test whether filtering is effective:
Excerpted from: adamboy’s blog