I'm reading data from an XML feed as follows:
$data=file_get_contents("mydata.rss");
$data=simplexml_load_string($data);
foreach($data->channel->item as $item){
$articles[] = array(
'description' => (string)$item->description,
'link' => (string)$item->link,
'pubDate' => (string)$item->pubDate,);
}
The issue is that the feed is very long with maybe 100 items. I only want read the first 10. I can work around this by manually setting a counter and then using an if statement within the foreach loop but I don't think that is the best approach as the entire feed is still be read and therefore unecessary overhead is added.
what's the most efficient way of achieving this without reading the entire feed?
Thanks in advance...