php 获取百度的热词数据的代码
php 获取百度的热词数据的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:tbody->tras$temp){if(!empty($temp->td->a)){$keyArray[]=trim((...

复制代码 代码如下:

<?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教程学习
编程开发子分类