Home >Backend Development >PHP Tutorial >A word filtering function_PHP tutorial

A word filtering function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:42:19808browse

function words($fileName,$word){
if (!file_exists($fileName))
{
return FALSE;
}

$badWords = file($fileName) ;
$word = trim($word);
$word = preg_replace(/d/,,$word);
$word = preg_replace(/[a-zA-Z]/,,$ word);
foreach ($badWords as &$v){
$v=trim($v);
}

if (in_array($word,$badWords)){
return TRUE;
}else{
foreach ($badWords as $vv){
if (strpos($word,$vv) !== false){
return TRUE; >Return value: TRUE means there are sensitive words, FALSE means there are no sensitive words





http://www.bkjia.com/PHPjc/486079.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/486079.htmlTechArticlefunction words($fileName,$word){ if (!file_exists($fileName)) { return FALSE; } $badWords = file($fileName); $word = trim($word); $word = preg_replace(/d/,,$word); $word = preg_repl...
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