当前位置:首页 > PHP教程 > PHP高级教程

php 获取百度的热词数据的代码

复制代码 代码如下:

<?php
/**
* 获取百度的热词
* @user 小杰
* @from http://www.isharey.com/?p=354
* @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("&", "&", $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;
}
print_r(getbaiduhotkeyword());

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!