欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php获取百度的热词数据

程序员文章站 2022-06-14 08:02:35
...

获取百度的热词

/**
 * 获取百度的热词
 * @user   小杰
 * @from   http://www.php.cn/
 * @return array  返回百度的热词数据(数组返回)
 */
function getBaiduHotKeyWord()
{
    $templateRss = file_get_contents('http://top.baidu.com/rss_xml.php?p=top10');
    If (preg_match('/<table>(.*)<\/table>/is', $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;
}
相关标签: php