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());

相关文章

Discuz Uchome ajaxpost小技巧

比如默认submit按钮这样操作:onclick="ajaxpost('formid')";之类的,我们可以先这样。。 onclick="$('__formid').innerText=...

PHP实现的敏感词过滤方法示例

本文实例讲述了PHP实现的敏感词过滤方法。分享给大家供大家参考,具体如下: 1、敏感词过滤方法 /** * @todo 敏感词过滤,返回结果 * @param array $li...

PHP基本语法实例总结

本文实例讲述了PHP基本语法。分享给大家供大家参考,具体如下: Demo1.php <?php //echo 表示向浏览器输出,echo 其实是一个函数 //双...

PHP封装的PDO数据库操作类实例

本文实例讲述了PHP封装的PDO数据库操作类。分享给大家供大家参考,具体如下: <?php class DatabaseHandler { /** *...

PHP入门教程之图像处理技巧分析

本文实例讲述了PHP图像处理。分享给大家供大家参考,具体如下: Demo1.php <?php //一般生成的图像可以是 png,jpg,gif,bmp //j...