Fatal error: Call to a member function getElementsByTagName() WordPress 4.2.2 RSS Feed

Fatal error: Call to a member function getElementsByTagName() WordPress 4.2.2 RSS Feed

我收到 致命错误:当我尝试从我的 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;

如果有人能阐明这一点,那就太好了。

你可以这样使用:

$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,
    ));
}

祝你好运