当我试图从我的wordpress博客中提取RSS源时,我正在收到致命错误:调用成员函数getElementsByTagName()。这是我用来获取RSS源的代码(直到最近才开始运行):
$xmlDoc = new DOMDocument();
@$xmlDoc->load('http://www.revolutionpersonaltraining.com.au/blog/feed/');
$x = $xmlDoc->getElementsByTagName('item');
for ($i=0; $i<6; $i++):
$items[$i]['date'] = strftime("%Y-%m-%d %H:%M:%S", strtotime($x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue));
$items[$i]['title'] = $x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$items[$i]['link'] = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$items[$i]['desc'] = $x->item($i)->getElementsByTagName('encoded')->item(0)->childNodes->item(0)->nodeValue;
endfor;
如果有人能对此有所了解,那就太棒了。
答案 0 :(得分:2)
您可以这样使用:
$feed = new DOMDocument();
$feed->load('http://www.revolutionpersonaltraining.com.au/blog/feed/');
$items = array();
foreach ($feed->getElementsByTagName('item') as $item) {
array_push($items, array (
'title' => $item->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $item->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $item->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $item->getElementsByTagName('pubDate')->item(0)->nodeValue,
));
}
祝你好运