php - explode and in_Array search not working -
ok here code codepad here 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 $wordtmp) { if (!empty($wordtmp) && !in_array($wordtmp, $omit) && strlen($wordtmp) >= $min_count) { $words[] = $wordtmp; } } return $words; }
ok function should return array of words filtering $omit
variable. when use words in first $omit
array filtered, second merged $exclude_list
not filtered.
i use function way :
$filter_array = explode("\n", words list separated \n new line here); print_r(processcontent('string gere filtering', $min_word_length, $filter_array));
the variable $filter_array
passed in exclude_list merged omit variable not filtered in return value. first $omit
value filtered. there wrong in code??
the problem because $filter_array
has spaces in it. either:
$filter_array = array_map(function($el) { return trim($el); }, $filter_array);
or
foreach ($filter_array &$element) { $element = trim($element); }
Comments
Post a Comment