Example of using PHP to filter blacklist keywords

Source: Internet
Author: User
Keyword filtering is very simple. the content to be filtered is stored in an array or a document. when the user submits the content, we can determine whether to use preg_match or istrpos. the specific method is as follows. for example, the code is as follows: filter the blacklist keyword function fu... keyword filtering is very simple. the content to be filtered is stored in an array or a document. when the user submits the content, we can determine whether to use preg_match or istrpos. the specific method is as follows.

For example, the code is as follows:

// Filter the blacklist keyword function

Function check _ ($ data) {$ keywords = "are you a great God | Hello | go to death"; if (preg_match ("/$ keywords/I", $ data )) {return;} else {return $ data ;}}

The keyword is stored in txt and txt files in this form: | gambling machine | selling blood | selling kidney | selling organs | cornea, the code is as follows:

 "; // Var_dump ($ w); // $ words =" aaa | bbb | ccc | ddd | eee "; $ matched = preg_replace ('/'. $ word. '/I', '***', $ string); return $ matched; // open source code phprm.com} $ content = "I want aaafsdfbbb "; if ($ result = Filter_word ($ content ,'. /words.txt ') {echo $ result; echo "replaced successfully";} else {echo "failed to be replaced! ";}


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.