Is there any way to still make use of all the feeds but instead of loading all the 25 posts of every feed (<entry></entry>
o开发者_StackOverflow社区r <item></item>
), to get the first 10 posts of every feed.
$feeds = array('',''); //a looot of inputs
$entries = array();
foreach ($feeds as $feed) {
$xml = simplexml_load_file($feed);
$xml->registerXPathNamespace('f', 'http://www.w3.org/2005/Atom');
$entries = array_merge($entries, $xml->xpath('/f:feed/f:entry | /rss/channel//item'));
}
Try this:
$entries = array();
foreach ($feeds as $feed) {
$xml = simplexml_load_file($feed);
$xml->registerXPathNamespace('f', 'http://www.w3.org/2005/Atom');
$entries = array_merge($entries, $xml->xpath('/f:feed/f:entry[position() <= 10] | /rss/channel//item[position() <= 10]') );
}
This uses position()
.
精彩评论