0
我正在使用SimpleXML讀取包含我網站新聞和事件的XML文件。我使用foreach來循環我的預定義的xml標記。然而,在我的網站上,我只需要提供三個新聞和事件,這是我xml根目錄的孩子。SimpleXML僅讀取特定數量的孩子
<list>
<newsevent>
<date>AUG 7</date>
<description>news</description>
</newsevent>
<newsevent>
<date>AUG 6</date>
<description>news/description>
</newsevent>
<newsevent>
<date>AUG 5</date>
<description>news</description>
</newsevent>
</list>
我使用foreach循環從我的PHP文件
foreach($xml->newsevent as $newsevent)
{
echo "$newsevent->date";
echo "$newsevent->description";
}
的XML文件將被視爲數據庫的新聞和事件,顯然會有很多紀錄。我怎麼能只顯示特定數量的新事件?
非常感謝 – user874737