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学习笔记之session

cookie和session是web开发新手容易搞混的两个概念,弄清楚两者有助于对web交互更好的理解。个人认为session和cookie的区别主要有如下几点: cookie 信息保存...

PHP 配置文件中open_basedir选项作用

如下是php.ini中的原文说明以及默认配置: ; open_basedir, if set, limits all file operations to the defined dir...

php通用检测函数集合第1/3页

<?  //【警告】:未经许可请勿随便修改  //-------------------------------------------------------...

php获取本周星期一具体日期的方法

本文实例讲述了php获取本周星期一具体日期的方法。分享给大家供大家参考。具体如下: private function mondayTime($timestamp=0,$is_retu...

试用php中oci8扩展

给大家分享个php操作Oracle的操作类 Oracle_db.class.php <?php class Oracle_db{ public $link; p...