我已经使用这个 php 来获取我博客的最新帖子:
function read_rss($display=0,$url='') {
$doc = new DOMDocument();
$doc->load($url);
$itemArr = array();
foreach ($doc->getElementsByTagName('item') as $node) {
if ($display == 0) {
break;
}
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
);
array_push($itemArr, $itemRSS);
$display--;
}
return $itemArr;
}
我从教程中学到了这一点,因为我不确定如何完成这项任务。但是它可以工作,但是我的错误日志中不断打印此错误:
[12-Jun-2010 06:13:36] PHP Warning: DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: Document is empty in http://www.prettyklicks.com/blog/?feed=rss2, line: 1 in public_html/includes/functions.php on line 153
[12-Jun-2010 06:13:36] PHP Warning: DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: Start tag expected, '<' not found in http://www.prettyklicks.com/blog/?feed=rss2, line: 1 in public_html/includes/functions.php on line 153
有任何想法吗?
谢谢!