wordMaxLen = $len > $this->wordMaxLen ? $len : $this->wordMaxLen; $this->dict[$word] = 1; } function removeWord($word) { unset($this->dict[$word]); } function match($str, &$matched) { if(mb_strlen($str) < 1) { return; } $len = $this->wordMaxLen; while($len>0) { $substr = mb_substr($str, 0, $len, 'utf-8'); if(isset($this->dict[$substr])) { $matched[] = $substr; break; } else { $len--; } } if($len == 0) { $len = 1; } $str = mb_substr($str, $len,null, 'utf-8'); $this->match($str, $matched); } }