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中将数组转成字符串并保存到数据库中的函数代码

复制代码 代码如下:/** * 将字符串转换为数组 * * @param    string  $data   字符串 * @...

php中数字、字符与对象判断函数用法实例

本文实例讲述了php中数字、字符与对象判断函数用法。分享给大家供大家参考。具体分析如下: 在php判断数字,字符,对象,数组等包括有参见 is_bool()、is_int()、is_in...

深入解析PHP垃圾回收机制对内存泄露的处理

上次说到了refcount和is_ref,这里来说说内存泄露的情况复制代码 代码如下:$a = array(1, 2, &$a);unset($a);在老的PHP版本中,这里就会出现内存...

php获取当前url地址的方法小结

本文实例讲述了php获取当前url地址的方法。分享给大家供大家参考,具体如下: js 获取: top.location.href //顶级窗口的地址 this.location.h...

如何使用脚本模仿登陆过程

查看他的登陆页面的代码, 看他提交到哪个页面, 变量是什么。复制代码 代码如下:<form method="post" action="lo...