爆炸和in_Array搜索不起作用

时间:2011-02-18 11:55:31

标签: php

  

可能重复:
  explode and in_Array search not working

这里的键盘http://codepad.org/ZQz0Kn3R

function processContent($content, $min_count = 2, $exclude_list = array()) {
    $wordsTmp = explode(' ', str_replace(array('(', ')', '[', ']', '{', '}', "'", '"', ':', ',', '.', '?'), ' ', $content));
    $words = array();
$wordsTmp2 = array();
$omit = array('and', 'or', 'but', 'yet', 'for', 'not', 'so', '&', '&', '+', '=', '-', '*', '/', '^', '_', '\\', '|');
if(count($exclude_list)>0){
    $omit = array_merge($omit, $exclude_list);
}
foreach ($wordsTmp as $wordTmp) {
   if (!empty($wordTmp) && !in_array($wordTmp, $omit) && strlen($wordTmp) >= $min_count) {
             $words[] = $wordTmp;
    }
}
return $words;
}
$filter_array = explode("\n", words list separated by \n new line here);
print_r(processContent('String gere for filtering', $min_word_length, $filter_array));

变量$ filter_array传入exclude_list也被合并为省略变量,但不会在返回值中过滤。只过滤了第一个$ omit值。代码中有什么问题吗?

1 个答案:

答案 0 :(得分:0)

你错过了“你的第16行。



$filter_array = explode("\n", "words list separated by \n new line here");