Home >php教程 >PHP源码 >php获取百度的热词数据

php获取百度的热词数据

PHP中文网
PHP中文网Original
2016-05-25 17:12:001229browse

获取百度的热词    

/**
 * 获取百度的热词
 * @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(&#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;
}

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP检测 ajax 请求Next article:一个简单的memcache类