Unlike the use of their own server for Word segmentation, discuz! online Chinese word breaker is based on the API return word segmentation results. In the project, we only need a function to easily do word segmentation, keyword extraction.
The following is a function written according to the discuz! online word breaker API, and the test is functioning correctly:
Copy CodeThe code is as follows:
/**
* DZ Online Chinese participle
* @param the title of a participle $title string
* @param the contents of a word $content string
* @param data encoding returned $encode the string API
* Array of keywords obtained @return array
*/
function dz_segment ($title = ', $content = ', $encode = ' utf-8 ') {
if ($title = = ") {
return false;
}
$title = Rawurlencode (Strip_tags ($title));
$content = Strip_tags ($content);
if (strlen ($content) >2400) {//Online word breaker service has a 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); Reads the data from the XML into the array object
$result = $xml _array->keyword->result;
$data = Array ();
foreach ($result->item as $key = + $value) {
Array_push ($data, (string) $value->kw);
}
if (count ($data) > 0) {
return $data;
}else{
return false;
}
}
Word breaker example, accessed via URL:
Copy CodeThe code is as follows: Http://keyword.discuz.com/related_kw.html?title= high-grade history review of high-quality tutorials &content=&ics=utf-8&ocs=utf-8
The XML data returned:
Copy the Code code as follows:
36000
1
0
1291287160
0
高三历史
http://www.bkjia.com/PHPjc/740208.html www.bkjia.com true http://www.bkjia.com/PHPjc/740208.html techarticle Unlike the use of their own server for Word segmentation, discuz! online Chinese word breaker is based on the API return word segmentation results. In the project, we only need a function to easily make participle ...