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利用hash冲突漏洞进行DDoS攻击的方法分析

本文实例分析了PHP利用hash冲突漏洞进行DDoS攻击的方法。分享给大家供大家参考。具体分析如下: 首先声明:本文内容只用于研究学习使用,请勿用于非法行为! 前面提到过最近爆出的has...

php反射学习之不用new方法实例化类操作示例

本文实例讲述了php反射学习之不用new方法实例化类操作。分享给大家供大家参考,具体如下: 上一篇php反射入门示例简单介绍了 php 反射的几个常见类的使用方法,但是用反射能做些什么,...

php中switch语句用法详解

本文介绍php中的switch语句的用法,它跟其他语句中的switch用法差不多的,但注意有有一个break语句。 PHP中switch语句的标准语法: switch (expre...

php获取url字符串截取路径的文件名和扩展名的函数

php获取文件名复制代码 代码如下: function retrieve($url) { preg_match('/\/([^\/]+\.[a-z]+)[^\/]*$/',$url,$m...

支持数组的ADDSLASHES的php函数

复制代码 代码如下://SQL ADDSLASHES function saddslashes($string) { if(is_array($string)) { foreach($s...