• 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." </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]." </div>";
    }
    }
    

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

      

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

      

    文章转自:http://www.kaotop.com/it/640618.html

      

    千行代码,Bug何处藏。 纵使上线又怎样,朝令改,夕断肠。
  • 相关阅读:
    装饰者模式和适配器模式
    java 中获得 资源文件方法
    在windows 上统计git 代码量
    Linux-静态库生成
    Redis-Redi事务注意事项
    Linux-使用 yum 升级 gcc 到 4.8
    Linux-配置虚拟IP
    PHP-PSR-[0-4]代码规范
    Linux-/etc/rc.local 或 service 中使用 sudo -u xxx cmd 执行失败(sorry, you must have a tty to run sudo)解决办法
    Linux-系统负载
  • 原文地址:https://www.cnblogs.com/68xi/p/15648354.html
Copyright © 2020-2023  润新知