Home > php教程 > php手册 > php file_get_contents获取百度热词代码

php file_get_contents获取百度热词代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:01:13
Original
1688 people have browsed it

这是一段很简单的程序利用了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('/

(.*)
/is', $templateRss, $_description)) {
        $templateRss = $_description [0];
        $templateRss = str_replace("&", "&", $templateRss);
    }
    $templateRss = "" . $templateRss;
    $xml = simplexml_load_String($templateRss);
    foreach ($xml->tbody->tr as $temp) {
        if (!empty ($temp->td->a)) {
            $keyArray [] = trim(($temp->td->a));
        }
    }
    return $keyArray;
}
Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template