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获取文件行数的方法

本文实例讲述了PHP获取文件行数的方法。分享给大家供大家参考。具体分析如下: 提供两种实现方法,虽然第二种简单易懂,但是第一种效率最好 第一种: <?php $fil...

基于PHP导出Excel的小经验 完美解决乱码问题

我在PHP项目里要求把数据导出为Excel,并且数据中包含中文.网上大概了解一下可是使用PHPExcel,可是相对我的需求,这个框架太复杂了.于是还是想找找简单做法.网上发现其实最简单可...

php function用法如何递归及return和echo区别

复制代码 代码如下: <?php //模拟sql数据 $array = array(0=>'apple',1=>'banana',2=>'cat',3=>'...

功能强大的PHP发邮件类

本文示例为大家分享了强大的PHP发邮件类,供大家参考,具体内容如下 <?php class smtp { var $smtp_port; var $time_out;...

解析php中如何直接执行SHELL

$message=shell_exec("sudo /usr/local/webserver/nginx/sbin/nginx -t 2>&1");echo "运行结果:".$me...