我已经完成了对此的搜索,但是我还没有找到正在寻找的东西。我使用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