【发布时间】:2016-09-19 13:29:03
【问题描述】:
我正在使用 Simplepie 解析不同的 RSS 提要,将它们传递给 Smarty 模板,并且我需要从每个项目行返回属性,在此示例中显示为:NEWSX
<source url="http://whatever.url/"><![CDATA[NEWSX]]></source>
我发现 get_item_tags 方法将选择使用以下内容的行和属性:
$newssource = $item->get_item_tags('','source');
这是我的问题。使用以下代码时,我不知道如何将每个源附加到一个项目(这样基本上我每次都可以在通常的标题、链接、描述等旁边显示不同的源元素):
$RSS = array();
foreach($items as $item){
$feed = $item->get_feed();
$tmp=array();
$newssource = $item->get_item_tags('','source');
echo $newssource[0]["data"];
if ($feed){
if ($enclosure = $item->get_enclosure()){
$tmp['title'] = $item->get_title();
$tmp['permalink'] = $item->get_permalink();
$tmp['thumbnail'] = $enclosure->get_thumbnail();
$tmp['description'] = $enclosure->get_description();
$tmp['image'] = $enclosure->get_link();
}
$tmp['date'] = $item->get_date('j M Y');
$tmp['content'] = $item->get_content();
$tmp['title'] = $item->get_title();
$tmp['link'] = $item->get_link();
$tmp['description'] = $item->get_description();
array_push($RSS, $tmp);
}
}
可以吗?提前感谢您的任何帮助或建议。
【问题讨论】: