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分页显示制作详细讲解

每页多少条记录($PageSize)?   当前是第几页($CurrentPageID)?   现在只要再给我一个结果集,我就可以显示某段特定的结果出来。   至于其他的参数,比如:上一...

PHP封装的多文件上传类实例与用法详解

本文实例讲述了PHP封装的多文件上传类实例与用法。分享给大家供大家参考,具体如下: <?php /**//* * @(#)UploadFile.php * * 可...

php array_unique之后json_encode需要注意

例如:array_unique(array(1, 1, 2)); 他的结果是 array(2) { [0]=> int(1) [2]=> int(2) } 这就不是numer...

PHP大批量数据操作时临时调整内存与执行时间的方法

复制代码 代码如下:ini_set('memory_limit', '250M'); //内存限制 set_time_limit(0); //...

PHP删除指定目录中的所有目录及文件的方法

本文实例讲述了PHP删除指定目录中的所有目录及文件的方法。分享给大家供大家参考。具体实现方法如下: <?php /* * * 删除指定目录中的所有目录及文件(或者...