2011-11-02 36 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