Home >Backend Development >PHP Tutorial >Example of filtering sensitive words in php_PHP tutorial

Example of filtering sensitive words in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:571132browse

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...
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