这里有我的代码:
<?php
$url = "http://feeds.hipertextual.com/alt1040";
$rss = simplexml_load_file($url);
if($rss) {
$items = $rss->channel->item;
foreach($items as $item) {
$title = $item -> title;
$link = $item -> link;
$description = $item -> description;
$replace = preg_replace("/<img[^>]+\>/i", "", $description);
echo utf8_decode("<h3><a href=$link>$title</a></h3>");
echo utf8_decode("<p>$replace</p>");
}
}
?>
我从该 URL 获取 RSS 并对其进行解析,这样图像就不会出现。直到这里OK。但现在,我只想显示来自 RSS Feed 的第一条新闻,而不是所有新闻。
如果我数了数,就会发现有 25 条新闻。
$count = count ($items);
echo $count; //25 news...
我该怎么做才能只显示第一条新闻?