Example of filtering sensitive words in php_PHP tutorial

WBOY
Release: 2016-07-13 10:34:57
Original
1086 people have browsed it

Copy code The code is as follows:

$badword = array(
'Zhang San','Zhang Sanfeng',' Zhang San Toyota'
);
$badword1 = array_combine($badword,array_fill(0,count($badword),'*'));
$bb = 'I drove Zhang San Toyota today Go to work';
$str = strtr($bb, $badword1);
echo $str;

Copy code The code is as follows:

$hei=array(
'China',
'Japan'
);
$blacklist="/".implode("|",$hei)."/i";
$str="China is a very good country";
if(preg_match($blacklist, $str, $matches)){
print "found:". $matches[0];
} else {
print "not found.";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/747678.htmlTechArticleCopy the code The code is as follows: $badword = array( 'Zhang San','Zhang Sanfeng','Zhang San Toyota' ); $badword1 = array_combine($badword,array_fill(0,count($badword),'*')); $bb = 'I drove Zhang San today...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!