我已經完成了對此的搜索,但是我還沒有找到正在尋找的東西。我使用simpleXML來解析我所做的RSS提要,並且它非常適合只顯示一個條目。我正試圖修改這個方法,只是拉最近更新的條目。我如何得到它來更新或只是拉最近的條目?使用SimpleXML顯示最新的XML訂閱源條目
這就是我現在解析RSS提要,並顯示一個單一的條目,但是,這是我卡住,因爲我只是想顯示最近的條目。
這只是解析提要最相關的代碼片段。
//Set initial output to false
$tData = false;
for($i = 0; $i < 1; $i++){
$location = $xml->reports[$i]->location;
$upperCase = strtoupper($location);
$report = $xml->reports[$i]->report;
$timestamp = $xml->reports[$i]->timestamp;
$updateTime = DATE("g:i A", STRTOTIME($timestamp));
// Set table style
$tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};";
$td1Style = "{$tbrdr};{$sbrdr}; text-align:center; font-size: 11px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};";
$td2Style = "{$sbrdr}; text-align:center; font-size: 12px; padding: 1px 0px 1px 0px; background-color:{$bkgColor};";
$td3Style = "{$sbrdr}; {$bbrdr}; text-align:center; background-color:{$bc};";
// construct data for table display
$tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
$tData .= "<tbody>\n";
$tData .= " <tr><td style='{$td1Style}'>LATEST LOCAL STORM REPORT</td></tr>\n";
$tData .= " <tr><td style='{$td2Style}'><b>{$report}</b> - <span style='color: rgb(204, 102, 0);'>{$upperCase} - {$updateTime}</span></td></tr>\n";
$tData .= " <tr><td style='{$td3Style}'><a href='wxmesqLSR.php' title='Click to view the details'>Click here for details</a></td></tr>\n";
$tData .= "</tbody>\n";
$tData .= "</table>\n";
$tData .= $afterTable;
}
編輯:示例XML文件
<?xml version="1.0"?>
<entrys>
<reports>
<timestamp>Thu, 11 Jul 2013 23:19:39 -0500</timestamp>
<name>Mesquite Weather</name>
<location>Mesquite</location>
<report>GENERAL</report>
<description>Official MW test</description>
</reports>
<reports>
<timestamp>Fri, 12 Jul 2013 00:44:39 -0500</timestamp>
<name>Mesquite Weather</name>
<location>Sunnyvale</location>
<report>DOWNED POWER LINES</report>
<description>Just an official MW test</description>
</reports>
</entrys>
-Thanks的!
你能提供正在處理的XML的樣本?我們需要知道什麼標識了「最近的入口」 - 它是最後一個嗎?目前你的問題是你不知道在你的input-XML中有多少條目,並且只有一次循環(由'$ i <1'定義)。這可以使用XPath來解決,但不知道XML結構。 – tfoo
@tfoo定義了'$ i <1',所以它只返回一個條目。否則,如果有多個條目,它會顯示多個條目,我只想顯示一個條目,即最近的條目。我使用XML結構的示例更新了OP。 – Texan78