2011-11-02 74 views
0

我已經研究過這個,但在實現它到我的代碼時遇到了麻煩。我有:使用php解析rss feed中的不尋常標籤。 (有標籤<dc:author>)

<?php 
$rss = new DOMDocument(); 
$rss->load('FEEDURL'); 
$feed = array(); 
foreach ($rss->getElementsByTagName('item') as $node) { 
$item = array ( 
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 

//author 
'author' => $node->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/','dc') >item(0)->nodeValue 

); 
array_push($feed, $item); 
} 
?> 

該部分的評論//author是我有問題的地方。 RSS Feed中的標籤是<dc:author>

如果您有一篇我錯過的相關文章,請發送給我,不要投票。謝謝:)

+0

我知道這是不是問題,但如果你想爲了能夠閱讀幾乎所有的RSS/Atom feed,你應該看看[SimplePie](http://simplepie.org/)庫。 – Nicolas

回答

0

dc是命名空間,author是一個標籤名,因此,如果http://purl.org/dc/elements/1.1/是的namespaceURI爲dc你需要搜索這樣的:

$node->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/','author')

+0

哦!我現在明白了!非常感謝您的回覆!非常感謝! :) – Jason