Home  >  Article  >  Backend Development  >  PHP gets Baidu’s hot word data

PHP gets Baidu’s hot word data

巴扎黑
巴扎黑Original
2016-11-24 10:03:421299browse

/**
* Get Baidu’s hot words
* @user Xiaojie
* @from http://www.isharey.com/?p=354
* @return array Return Baidu’s hot word data (array return)
*/

Java code

/**

* Get Baidu’s hot words

* @user 小杰

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

* @return array Return Baidu’s hot word data (array return)

*/

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 internationalizationNext article:php internationalization