关于php:如何限制我保存在数组中的XML feed的内容?

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

有没有办法仍然利用所有的feed,而不是加载每个feed的25个post(来获得每个feed的前10个post?

1
2
3
4
5
6
7
8
9
10
11
$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'));

}


试试这个:

1
2
3
4
5
6
7
8
$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]') );
}

它使用position()