本文实例讲述了PHP获取百度收录、百度热词及百度快照的方法。分享给大家供大家参考。具体如下:
PHP;">
PHP;">
PHP
/**
* @return array 返回百度的热词数据(数组返回)
*/
function getBaiduHotKeyWord()
{
$templateRSS = file_get_contents('http://top.baidu.com/RSS_xml.PHP?p=top10');
if (preg_match('//is',$templateRSS,$_description)) {
$templateRSS = $_description [0];
$templateRSS = str_replace("&","&",$templateRSS);
}
$templateRSS = "" . $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());