Using DISCUZ keyword server to implement PHP Chinese participle

Source: Internet
Author: User

  This article mainly introduces the use of Discuz keyword server to implement the PHP Chinese Word segmentation method and code examples, the need for friends can refer to the following

Unlike the use of their own server for Word segmentation, discuz! online Chinese word segmentation service is based on the API to return word segmentation results. In the project, we only need a function to facilitate segmentation, keyword extraction. The following is based on the discuz! online Word service API written functions, testing can be normal operation:   code as follows:/**  * dz Online Chinese participle  * @param $title string for Word segmentation title  * @param $c Ontent string The content of the participle  * @param $encode The data encoding returned by the string API  * @return  array a keyword array  */ N dz_segment ($title = ', $content = ', $encode = ' utf-8 ') {    if ($title = = ") {        R Eturn false;    }     $title = Rawurlencode (Strip_tags ($title));     $content = Strip_tags ($content);     if (strlen ($content) >2400) {//Online participle service has length limit         $content =  MB_SUBSTR ($ Content, 0, $encode);    }     $content = Rawurlencode ($content);     $url = ' http://keyword.discuz.com/related_kw.html?title= '. $title. ' &content= '. $content. ' &ics= '. $encode. ' &ocs= '. $encode;     $xml _array=simplexml_load_file ($url);                       //read data from XML to an array object       $result = $xml _arra y->keyword->result;     $data = array ();     foreach ($result->item as $key => $value) {            Array_push ($data , (String) $value->kw);    }     if (count ($data) > 0) {        return $data;    }else{&nbs P       return false;    }     Participle example, access by URL:   Code as follows: Http://keyword.discuz.com/related_kw.html?title= high-grade history of the whole review of the fine course &content=&ics=utf-8&ocs=utf-8   returned XML data: Code as follows: <?xml version= "1.0" encoding= "Utf-8"?> < total_response>  <svalid>36000</svalid>  <keyword>  <info>   < count>1</count>   <errno>0</errno>   <nextuptime>1291287160</nextuptime >   <keep>0</keep>  </info>  <result>   <item>    <kw><! [cdata[history]]></kw>   </item>  </result>  </keyword> </total_response >

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.