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解析http获取的json字符串变量总是空白null

今天同事项目中遇到一个问题,通过http接口获取的json字符串使用json_decode始终无法正确解析,返回空白。 直接把结果字符串复制出来手动创建一个变量却正常,在前端js也能解析...

PHP 返回13位时间戳的实现代码

13位时间戳生成函数如下所示: private function getMillisecond() { list($t1, $t2) = explode(' ', microt...

php 中奖概率算法实现代码

实现代码: <?php /** *php 中奖概率算法 * */ function get_zj( $jp ,$glname = 'gl'){ $sum = 0...

在同一窗体中使用PHP来处理多个提交任务

为什么使用多个提交任务? 在我回答这个问题之前,先让我回答一个很显然的问题:既然许多窗体更适合单一的提交按钮,为什么有时人们需要的是两个(或者是更多)的提交按钮? 对这一问题最好的解释方...

php中用文本文件做数据库的实现方法

按我的经验,本人认为,以下列文件结构为最优:  ----------------------------------------------------------------...