A simple PHP content filtering instance _ PHP Tutorial

Source: Internet
Author: User
A simple PHP content filtering instance .? Phpif ($ _ POST) {two methods to convert the obtained file content to an array: * export fconfile_get_contents(.filter.txt); $ filter_wordexplode (n, $ fcon); * export filter_wordfile(.filter.txt)

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

{

If (preg_match ("/". (trim ($ filter_word [$ I]). "/I", $ str ))

{

Echo "script" alert ('the content you entered contains illegal content. please try again! '); Script ";

Echo "back ";

Exit;

}

}

Echo "the content you entered is:". $ str;

}

?>

Test whether the filter is effective:

From: blog of adamboy

Http://www.bkjia.com/PHPjc/478591.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478591.htmlTechArticle? Php if ($ _ POST) {// you can convert the file content to an array using the following two methods:/* $ fcon = file_get_contents (. /filter.txt); $ filter_word = explode (\ n, $ fcon); */$ filter_word = file (. /filter.txt )...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.