开发者

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

开发者 https://www.devze.com 2023-04-09 19:34 出处:网络
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

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

精彩评论

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