All the good time. parsing xml file:

$xml = simplexml_load_file('http://www.vesti.ru/vesti.rss'); 

I interrupt like this:

 $count=10; foreach ( $xml->channel->item as $key => $item) { ... код ... $i++; if($i == $count) break; } 

But it turns out that there are about 50 records in the record file (and, let's say, varied by that side), and it turns out I get only the very first ones, i.e. "old" 10. And how to implement reading it (xml-file) from the end?

    2 answers 2

     foreach ($xml->channel->item as $key => $item) { if ($i < 40) { continue; } if ($i > 50) { break; } // код } 
    • So ... Ie always need to know the exact number of entries in xml? And if the source will unilaterally change the number of records? Although the idea seems to be working, provided that the quantity is constant. - I_CaR 4:03

    Slightly upgraded code from @Etki:

     $count=10; $count_news=0; foreach ( $xml->channel->item as $key => $item) { $count_news++; } foreach ($xml->channel->item as $key => $item) { $i++; if ($i <= ($count_news-$count)) { continue; } else { [тут делаем свои дела] if($i == $count_news) break; } }