如果在数组中找到坏词之一,我有这个函数返回 true$stopwords
function stopWords($string, $stopwords) {
$stopwords = explode(',', $stopwords);
$pattern = '/\b(' . implode('|', $stopwords) . ')\b/i';
if(preg_match($pattern, $string) > 0) {
return true;
}
return false;
}
它似乎工作正常。
问题是当数组$stopwords
为空时(所以没有指定坏词),它总是返回真,就像空值被识别为坏词并且它总是返回真(我认为问题是这个但可能是另一个)。
谁能帮我解决这个问题?
谢谢