PHP头条
热点:

php file_get_contents获取百度热词代码


这是一段很简单的程序利用了php的file_get_contents函数来采集百度的数据,然后通过simplexml_load_String把它数据解析出来,这样数据就保存到了一个数组,我们就可以方便的利用了。
 代码如下 复制代码

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;
}

www.phpzy.comtrue/php/21722.htmlTechArticlephp file_get_contents获取百度热词代码 这是一段很简单的程序利用了php的file_get_contents函数来采集百度的数据,然后通过simplexml_load_String把它数据解析出来,这样数据就保存到了一个数组,...

相关文章

    暂无相关文章

PHP之友评论

今天推荐