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

yipeiwu_com6年前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());

相关文章

PHP遍历XML文档所有节点的方法

本文实例讲述了PHP遍历XML文档所有节点的方法。分享给大家供大家参考。具体实现方法如下: 1. contact.xml代码: <contact id="43956">...

PHP输出时间差函数代码

PHP输出时间差函数 复制代码 代码如下:<?php  date_default_timezone_set('PRC'); //默认时区  echo "今天:"...

php下实现一个阿拉伯数字转中文数字的函数

如果要用于金额的转换,对小数部分的处理要做一下修改 <?php function ch_num($num,$mode=true) { $char =&...

hadoop常见错误以及处理方法详解

1、hadoop-root-datanode-master.log 中有如下错误:ERROR org.apache.hadoop.hdfs.server.datanode.DataNod...

回答PHPCHINA上的几个问题:URL映射

PHPCHINA服务器搬迁后,我就基本上上不去了,只能用代理,郁闷。但用代理居然不能发帖,回帖。做为版主,深感遗憾,今天用代理上去看到了几个帖子,顺便在这里回答下。  &nbs...