PHP鍒╃敤Discuz鍏抽敭璇嶆湇鍔″櫒瀹炵幇涓枃鍒嗚瘝鐨勮В鍐冲姙娉
杩欑瘒鏂囩珷涓昏涓哄ぇ瀹惰缁嗕粙缁嶄簡PHP鍒╃敤Discuz鍏抽敭璇嶆湇鍔″櫒瀹炵幇涓枃鍒嗚瘝鐨勭畝鍗曠ず渚嬶紝鍏锋湁涓瀹氱殑鍙傝冧环鍊硷紝鍙互鐢ㄦ潵鍙傝冧竴涓嬨
鎰熷叴瓒g殑灏忎紮浼达紝涓嬮潰涓璧疯窡闅弍hp鏁欑▼鐨勫皬鐜叉潵鐪嬬湅鍚э紒
涓嶅悓浜庝娇鐢ㄨ嚜宸辩殑鏈嶅姟鍣ㄨ繘琛屽垎璇嶏紝Discuz!鍦ㄧ嚎涓枃鍒嗚瘝鏈嶅姟鏄熀浜嶢PI杩斿洖鍒嗚瘝缁撴灉鐨勩傚湪椤圭洰涓紝鎴戜滑鍙渶瑕佷竴涓嚱鏁板嵆鍙柟渚垮湴杩涜鍒嗚瘝銆佸叧閿瘝鎻愬彇銆備互涓嬫槸鏍规嵁Discuz!鍦ㄧ嚎鍒嗚瘝鏈嶅姟API鍐欑殑鍑芥暟锛屾祴璇曞彲姝e父杩愯锛
浠g爜濡備笅:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<code>/**
* DZ鍦ㄧ嚎涓枃鍒嗚瘝
* @param $title string 杩涜鍒嗚瘝鐨勬爣棰
* @param $content string 杩涜鍒嗚瘝鐨勫唴瀹
* @param $encode string API杩斿洖鐨勬暟鎹紪鐮
* @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){ //鍦ㄧ嚎鍒嗚瘝鏈嶅姟鏈夐暱搴﹂檺鍒
$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); //灏哫ML涓殑鏁版嵁,璇诲彇鍒版暟缁勫璞′腑
$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;
}
}
</code>
|
浠g爜濡備笅:
1
|
<code>http://keyword.discuz.com/related_kw.html?title=楂樹笁鍘嗗彶鍏ㄧ▼澶嶄範绮惧搧鏁欑▼&content=&ics=utf-8&ocs=utf-8</code>
|
杩斿洖鐨刋ML鏁版嵁锛
浠g爜濡備笅:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<code><?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></code>
|
娉細鍏充簬PHP鍒╃敤Discuz鍏抽敭璇嶆湇鍔″櫒瀹炵幇涓枃鍒嗚瘝鐨勭畝鍗曠ず渚嬬殑鍐呭灏卞厛浠嬬粛鍒拌繖閲岋紝鏇村鐩稿叧鏂囩珷鐨勫彲浠ョ暀鎰
浠ヤ笂灏辨槸PHP鍒╃敤Discuz鍏抽敭璇嶆湇鍔″櫒瀹炵幇涓枃鍒嗚瘝鐨勮В鍐冲姙娉曠殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒