首页  >  文章  >  后端开发  >  php 获取百度的热词数据

php 获取百度的热词数据

巴扎黑
巴扎黑原创
2016-11-24 10:03:421302浏览

/** 
* 获取百度的热词 
* @user   小杰 
* @from   http://www.isharey.com/?p=354 
* @return array  返回百度的热词数据(数组返回) 
*/ 

Java代码  

/** 

 * 获取百度的热词 

 * @user   小杰 

 * @from   http://www.isharey.com/?p=354 

 * @return array  返回百度的热词数据(数组返回) 

 */  

function getBaiduHotKeyWord()  
{  
    $templateRss = file_get_contents('http://top.baidu.com/rss_xml.php?p=top10');  
    If (preg_match(&#39;/<table>(.*)<\/table>/is&#39;, $templateRss, $_description)) {  
        $templateRss = $_description [0];  
        $templateRss = str_replace("&", "&amp;", $templateRss);  
    }  
    $templateRss = "<?xml version=\"1.0\" encoding=\"GBK\"?>" . $templateRss;  
    $xml = simplexml_load_String($templateRss);  
    foreach ($xml->tbody->tr as $temp) {  
        if (!empty ($temp->td->a)) {  
            $keyArray [] = trim(($temp->td->a));  
        }  
    }  
    return $keyArray;  
}


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
上一篇:php 国际化下一篇:php数据操作