0

我将时间戳存储在我的 xml 文档中,但是当尝试将它们用作与当前时间戳进行比较时,它不起作用?我也试图让它与 date() 一起工作,但它不会?我究竟做错了什么?

XML 看起来像这样:

<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
  <game id="83832">
    <opponent>Danielle</opponent>
    <oppid>101</oppid>
    <lastdraw>1</lastdraw>
    <turn>1</turn>
    <image>101b.png</image> 
    <nextdraw>1348156426</nextdraw>
    <infopop>0</infopop>
    <playertilesum>89</playertilesum>
    <oppnation>0</oppnation>
  </game>
  <game id="89939">
    <opponent>Bigscreen</opponent>
    <oppid>107</oppid>
    <lastdraw>3</lastdraw>
    <turn>2</turn>
    <image>107a.png</image>
    <nextdraw>1347913606</nextdraw>
    <infopop>0</infopop>
    <playertilesum>101</playertilesum>
    <oppnation>0</oppnation>
  </game>
</data>

我尝试做的是:

$timestamp = $_SERVER['REQUEST_TIME'];

$xml=simplexml_load_file('TEST.xml');

foreach ($xml->game as $game) {

    if($game->nextdraw < $timestamp){

         echo '['.$r.'] '.$game->nextdraw.'<br>';

    }
}

我只想显示不早于时间戳的游戏?我做这一切都错了吗?

4

1 回答 1

0

我在您的代码中没有发现任何问题。我运行它并得到:

[] 1348156426
[] 1347913606

你得到什么?

更新:为了检查条件是否正确执行,请改用以下foreach循环。

foreach ($xml->game as $game) 
{

    if($game->nextdraw < $timestamp)
    {

        echo "<br> Game's next draw is ". date('m/d/Y h:i:s A', (int)$game->nextdraw);
        echo "<br> Current time is ". date('m/d/Y h:i:s A', (int)$timestamp);
        echo '<br><br>['.$r.'] '.$game->nextdraw;

    }

}

于 2012-09-26T15:07:34.950 回答