其他分享
首页 > 其他分享> > destoon根据标题调取百度下拉+淘宝下拉词,增强页面相关性

destoon根据标题调取百度下拉+淘宝下拉词,增强页面相关性

作者:互联网

   

写了一个destoon根据标题调取百度下拉+淘宝下拉词函数,增强页面相关性,也可以用于自动分词,提取相关词,废话不多说。上代码!

   首先在/api/extend.func.php里加入:

  

//根据标题调取相关下拉
function getRelcontentbyTitle($title){
$word=$title;
$word=urlencode($word);
$s = file_get_contents('http://suggest.taobao.com/sug?extras=1&code=utf-8&callback=g_ks_suggest_callback&q='.$word);
preg_match('/\{.+\}/', $s, $m);
foreach (json_decode($m[0])->result as $v) {
    $arr[] = $v[0];
}
//print_r($arr);
if ($arr!==""){
//获取数组中元素的值如下:
foreach($arr as $key=>$value) {
   echo  "<div  style='margin-right:3px;line-height:2.2;' class='label label-warning'  >".$value."&nbsp;</div>";
    }
}
$data=file_get_contents('http://suggestion.baidu.com/su?wd='.$word);
$data=mb_convert_encoding($data, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
$data_temp=strpos($data,"x");
$data=substr_replace($data,"",$data_temp,17);
$data = trim($data,");");
$data = trim($data,"{");
$data=preg_replace("/q:.+?.e,/",'', $data);
$data = str_replace("[","",$data);
$data = str_replace("]","",$data);
$data = "[".$data."]";
$data = str_replace(",","},s:",$data);
$data = str_replace("s:","{\"s\":",$data);//复杂的处理,以符合json格式
$dc=json_decode($data);
for ($n=0; $n<=4; $n++)
{
$wd[$n]=$dc[$n]->s;
echo  "<div  style='margin-right:3px;line-height:2.2;' class='label label-warning'  >".$wd[$n]."&nbsp;</div>";
}
}

  然后在内容模板页面调用,例如:

  

 <span class="glyphicon glyphicon-tags">相关联想: {getRelcontentbyTitle($title)}</span>

文章转自:destoon根据标题调取百度下拉+淘宝下拉词函数,增强页面相关性_destoon-考高分网 (kaotop.com)icon-default.png?t=LA92http://www.kaotop.com/it/640618.html

效果是这样的:

标签:arr,destoon,word,com,replace,下拉词,data,调取
来源: https://blog.csdn.net/luo2424348224/article/details/121739947