我想用PHP打印/回显多个rss feed。现在我只能使用foreach获取一个RSS源来从feed中获取数据并中断以将项目数量限制为两个,如下所示:
<?php
// feed URL
$feed = simplexml_load_file('https://dyn.com/blog/feed/');
// items counter
$rssitem = 0;
foreach ($feed->channel->item as $item) {
$title = (string) $item->title;
$rsslink = (string) $item->link;
$pubDate = (string) $item->pubDate;
$subpubDate = substr($pubDate, 0,25);
$publisher = 'dyn.com';
print '<div>';
printf(
'<h2><a href="%s">%s</h2>
<p>published: %s via </p>
',
$rsslink,
$title,
$subpubDate,
);
echo '</div>>';
// limit number of items
if (++$rssitem == 2) break;
}
如果我想从2个(或更多)RSS源导出2个第一项并通过发布日期(pubDate)对数据进行排序,我可以使用什么?