php 获取百度的热词数据的代码
作者:bea
代码如下: <?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 (
代码如下:
<?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中shell脚本的使用方法分享
- php tp验证表单与自动填充函数代码
- PHP 设计模式之观察者模式介绍
- php模拟post行为代码总结(POST方式不是绝对安全)
- 用穿越火线快速入门php面向对象
- php重定向的三种方法分享
- php中echo()和print()、require()和include()等易混淆函数的区别
- 我的php学习笔记(毕业设计)
- PHP中运用jQuery的Ajax跨域调用实现代码
- 修改PHP的memory_limit限制的方法分享
- php中取得文件的后缀名?
- ThinkPHP写第一个模块应用
- for循环连续求和、九九乘法表代码
- phpmail类发送邮件函数代码
- 国外PHP程序员的13个好习惯小结
- php中用于检测一个地理IP地址是否可用的代码
- PHP类的静态(static)方法和静态(static)变量使用介绍
- php 删除一个数组中的某个值.兼容多维数组!