Home > Backend Development > PHP Tutorial > Implementation of PHP sensitive keyword filtering

Implementation of PHP sensitive keyword filtering

小云云
Release: 2023-03-21 17:52:02
Original
2909 people have browsed it

This article mainly shares with you the implementation method of PHP sensitive keyword filtering, hoping to help everyone.

$badword = array(
    '张三','张三丰','张三丰田','上班'
);
$badword1 = array_combine($badword,array_fill(0,count($badword),'*'));
$bb = '我今天开着张三丰田上班';
$str = strtr($bb, $badword1);
echo $str;
Copy after login
$hei=array(
    '中国',
    '日本'
);
$blacklist="/".implode("|",$hei)."/i";
$str="中国一是一个很好的国家";
if(preg_match($blacklist, $str, $matches)){
    print "found:". $matches[0];
} else {
    print "not found.";
}
Copy after login

Related recommendations:

php filtering sensitive character class example code

PHP implements filtering sensitive words in message messages

php Sensitive word filtering advanced version

The above is the detailed content of Implementation of PHP sensitive keyword filtering. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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