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

yipeiwu_com5年前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中请求url的五种方法总结

本文主要给大家介绍了关于php中请求url的五种方法,分享出来供大家参考学习,下面话不多说,来一起看看详细的介绍: 五种方法: 前三种都是php基本的文件操作函数 curl()...

PHP中函数rand和mt_rand的区别比较

PHP函数rand和mt_rand    mt_rand() 比rand() 快四倍      很多老的 libc 的随机数发生器具有一些不确定和未知的特性而且很慢。PHP 的 rand...

php动态绑定变量的用法

本文实例讲述了php动态绑定变量的用法。分享给大家供大家参考。具体如下: private function bindVars($stmt,$params) { if ($para...

php 判断页面或图片是否经过gzip压缩的方法

使用php判断页面或图片是否经过gzip压缩方法 1.使用get_headers 页面内容 <?php ob_start('ob_gzhandler'); // 开启...

php 获取可变函数参数的函数

func_num_args() 返回传递给该函数参数的个数 func_get_arg($arg_num) 取得指定位置的参数值,$arg_num位置index从0开始n-1。 func_...