最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Discuz關(guān)鍵詞服務(wù)器實(shí)現(xiàn)PHP中文分詞

 更新時(shí)間:2014年03月11日 10:31:16   作者:  
這篇文章主要介紹了使用Discuz關(guān)鍵詞服務(wù)器實(shí)現(xiàn)PHP中文分詞的方法以及代碼實(shí)例,需要的朋友可以參考下

不同于使用自己的服務(wù)器進(jìn)行分詞,Discuz!在線中文分詞服務(wù)是基于API返回分詞結(jié)果的。在項(xiàng)目中,我們只需要一個(gè)函數(shù)即可方便地進(jìn)行分詞、關(guān)鍵詞提取。
以下是根據(jù)Discuz!在線分詞服務(wù)API寫的函數(shù),測試可正常運(yùn)行:

復(fù)制代碼 代碼如下:

/**
 * DZ在線中文分詞
 * @param $title string 進(jìn)行分詞的標(biāo)題
 * @param $content string 進(jìn)行分詞的內(nèi)容
 * @param $encode string API返回的數(shù)據(jù)編碼
 * @return  array 得到的關(guān)鍵詞數(shù)組
 */
 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){ //在線分詞服務(wù)有長度限制
        $content =  mb_substr($content, 0, 800, $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);                        //將XML中的數(shù)據(jù),讀取到數(shù)組對(duì)象中 
    $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;
    }
 }

分詞示例,通過url訪問:
復(fù)制代碼 代碼如下:
http://keyword.discuz.com/related_kw.html?title=高三歷史全程復(fù)習(xí)精品教程&content=&ics=utf-8&ocs=utf-8

返回的XML數(shù)據(jù):

復(fù)制代碼 代碼如下:
<?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[高三歷史]]></kw>
  </item>
 </result>
 </keyword>
</total_response>

相關(guān)文章

最新評(píng)論

磐安县| 岚皋县| 吉木乃县| 涟水县| 库伦旗| 肇东市| 台州市| 开封县| 六安市| 洪洞县| 昭平县| 万山特区| 阳东县| 萨迦县| 金沙县| 互助| 甘谷县| 那坡县| 军事| 凤翔县| 顺平县| 乌兰察布市| 申扎县| 松滋市| 罗城| 西盟| 苗栗市| 昌黎县| 广灵县| 会泽县| 博爱县| 长治县| 临夏县| 嘉善县| 秀山| 大化| 绍兴市| 泽库县| 新安县| 卢龙县| 鹰潭市|