开发者

How to limit the content of XML feeds I save in an array?

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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜