【发布时间】:2012-02-28 20:23:00
【问题描述】:
如果在数组$stopwords 中找到其中一个坏词,我有这个函数返回true
function stopWords($string, $stopwords) {
$stopwords = explode(',', $stopwords);
$pattern = '/\b(' . implode('|', $stopwords) . ')\b/i';
if(preg_match($pattern, $string) > 0) {
return true;
}
return false;
}
它似乎工作正常。
问题是当数组$stopwords 为空时(所以没有指定坏词),它总是返回true,就像空值被识别为坏词并且它总是返回true(我认为问题是这个,但也许是另一个)。
谁能帮我解决这个问题?
谢谢
【问题讨论】:
标签: php stop-words