A case of PHP Chinese word function code

Source: Internet
Author: User
Tags rtrim
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;? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.