Home>Article>Backend Development> PHP implements filtering sensitive words in message messages

PHP implements filtering sensitive words in message messages

巴扎黑
巴扎黑 Original
2017-03-22 14:29:01 3454browse

PHP implements filtering sensitive words in message messages

One code

    检测留言信息的敏感词 
姓 名: *
标 题: *
内 容: *
alert('留言信息中包含敏感词!');history.back(-1);"; exit; } } } } ?>

Two running results

PHP implements filtering sensitive words in message messages

Three code analysis

When the user submits a message, the program will use the regular expression preg_mctch() function to compare the message information with the sensitive words stored in the array to check whether the message submitted by the user contains Sensitive words. If the message contains sensitive words, a prompt message will pop up, otherwise the message information will be published successfully.

The "/i" in the preg_match() function means that letters are not case-sensitive when comparing sensitive words.

The above is the content of PHP's implementation of filtering sensitive words in message messages. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!

Related articles:

An efficient sensitive word filtering method (PHP)

Use PHP extension trie_filter to filter Chinese sensitive words

php sensitive word filtering uses a third-party extension trie_filter

Statement:
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