下面大致是我用来显示提要中的项目的内容。它工作正常,但提要有很多项目,我希望能够只显示提要中的前 5 个项目。这怎么办?
<?php
$theurl = 'http://www.theurl.com/feed.xml';
$xml = simplexml_load_file($theurl);
$result = $xml->xpath("/items/item");
foreach ($result as $item) {
$date = $item->date;
$title = $item->title;
echo 'The title is '. $title.' and the date is '. $date .'';
} ?>