当前位置: 移动技术网 > IT编程>开发语言>PHP > php 获取百度的热词数据的代码

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

2019年04月17日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<?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());

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网