For everyone to introduce a PHP Chinese word function, may be used in some occasions, the need for friends, refer to it. The code is as follows:
TRUE, ' segment_english ' = FALSE); var $dict _name = ' Unknown '; var $dict _words = array (); function Setlowercase ($value) { if ($value) {$this->options[' lowercase ') = TRUE;} else {$this->options[' lowercase '] = FALSE;} return TRUE;} function Setsegmentenglish ($value) {if ($value) {$this->options[' segment_english '] = TRUE;} else {$this->options [' segment_english '] = FALSE;} return TRUE;} function load ($dict _file) {if (!file_exists ($dict _file)) {return FALSE;} $fp = fopen ($dict _file, ' R '), $temp = Fgets ($fp, 1024x768), if ($temp = = = False) {return false;} else {if (Strpos ($temp, "t")! = = FALSE) {list ($dict _type, $dict _name) = Explode ("T", trim ($temp)),} else {$dict _type = trim ($temp); $dict _name = ' Unknown ';} $this->dict_name = $dict _name;if ($dict _type!== ' Dict_word_w ') {return FALSE;}} while (!feof ($fp)) {$this->dict_words[rtrim (fgets ($FP, 32))] = 1;} Fclose ($FP); return TRUE;} function Getdictname () {return $this->dict_name;} function segmentstring ($STR) {if (count ($this->dict_words) = = = 0) {return FALSE;} $lines = Explode ("n", $str), return $this->_segmentlines ($lines);} function Segmentfile ($filename) {if (count ($this->dict_words) = = = 0) {return FALSE;} $lines = file ($filename); return $this->_segmentlines ($lines);} function _segmentlines ($lines) {$contents _segmented = '; foreach ($lines as $line) {$contents _segmented. = $this->_ Segmentline (RTrim ($line)). "N";} do {$contents _segmented = Str_replace (",", $contents _segmented);} while (Strpos ($contents _segmented, ')!== FALSE); return $contents _segmented;? > |