Home > Backend Development > PHP Tutorial > A simple PHP content filtering example_PHP tutorial

A simple PHP content filtering example_PHP tutorial

WBOY
Release: 2016-07-13 17:46:29
Original
814 people have browsed it

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478591.htmlTechArticle?php 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)...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template