我試圖返回最後排序的固定數量的XML節點,以便我可以顯示「最近添加的」篩選器。我沒有存儲日期。如何使用PHP過濾最後10個節點?解析上次使用PHP排序的固定數量的XML子節點
XML:
<?xml version="1.0" encoding="utf-8"?>
<trackList>
<track>
<title>Lost in the Star</title>
<creator>Toshiki Hayashi</creator>
<cover>images/thinlines.jpg</cover>
<location>mp3/toshiki hayashi - lost in the star.mp3</location>
<genre>hip-hop</genre>
<playlist>2</playlist>
</track>
<track>
<title>Black Orpheusr</title>
<creator>Ouska</creator>
<cover>images/ouska.jpg</cover>
<location>mp3/ouska - Black Orpheus.mp3</location>
<genre>rock</genre>
<playlist>2</playlist>
</track>
<track>
<title>Soul Below</title>
<creator>Ljones</creator>
<cover>images/Ljones.jpg</cover>
<location>mp3/Ljones - Soul Below.mp3</location>
<genre>hip-hop</genre>
<playlist>2</playlist>
</track>
</trackList>
PHP:
<?php
$xml = new SimpleXMLElement('playlist100.xml', NULL, TRUE);
foreach($xml->xpath('//track[playlist="1"]') as $child)
{
echo '<div class="song"><a href="' . $child->location . '">';
echo '<img src="' . $child->cover . '" alt="cover" />';
echo '<span class="artist">' . $child->creator . '</span>';
echo '<span class="songTitle">' . $child->title . '</span></a></div>';
}
?>
請提供一些代碼你如何試圖至今。 –
的XML –
你在哪裏存儲數據? –