有没有办法在下面提到的坏词过滤器代码中实现 if else ,这样当用户输入任何坏词时,它会给出错误“您的输入包含不允许的词”而不是替换坏词
FUNCTION BadWordFilter(&$text, $replace){
$file_array = file('/path/to/badword.txt');
$bads = array();
foreach ($file_array as $word_combo) {
$bads[] = explode(',', $word_combo);
}
IF($replace==1) { //we are replacing
$remember = $text;
FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word
$text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it
}
IF($remember!=$text) RETURN 1; //if there are any changes, return 1
} ELSE { //we are just checking
FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word
IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1
}
}
}
$any = BadWordFilter($qtitle,1);
$any = BadWordFilter($qtitle,0);