<? Php
If ($ _ POST)
{
// You can convert the file content to 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 <count ($ filter_word); $ I ++)
{
If (preg_match ("/". (trim ($ filter_word [$ I]). "/I", $ str ))
{
Echo "<script> alert ('the content you entered contains illegal content. Please try again! '); </Script> ";
Echo "<a href = 'index. php'> return </a> ";
Exit;
}
}
Echo "the content you entered is:". $ str;
}
?>
<H2> test whether the filter is effective:
<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>
From: blog of adamboy