0

PHPを使用して日付でxmlデータをフィルタリングしたい

<xml>
<customer>
  <cid>1</cid>
  <amount_paid>1000</amount_paid>
  <date>2012-01-10</date>
</customer>
<customer>
  <cid>2</cid>
  <amount_paid>3000</amount_paid>
  <date>2012-01-10</date>
</customer>
<customer>
  <cid>3</cid>
  <amount_paid>1000</amount_paid>
  <date>2012-01-05</date>
</customer>
<customer>
  <cid>6</cid>
  <amount_paid>7000</amount_paid>
  <date>2012-01-21</date>
</customer>
</xml>

xml を日付でフィルタリングするにはどうすればよいですか? 例えば。date = "2012-01-10" の顧客を取得したい

4

1 に答える 1

1

実際に見る

<?php
    $string = '<xml>
<customer>
  <cid>1</cid>
  <amount_paid>1000</amount_paid>
  <date>2012-01-10</date>
</customer>
<customer>
  <cid>2</cid>
  <amount_paid>3000</amount_paid>
  <date>2012-01-10</date>
</customer>
<customer>
  <cid>3</cid>
  <amount_paid>1000</amount_paid>
  <date>2012-01-05</date>
</customer>
<customer>
  <cid>6</cid>
  <amount_paid>7000</amount_paid>
  <date>2012-01-21</date>
</customer>
</xml>';

$xml = simplexml_load_string($string);

foreach ($xml->customer AS $customer)
{
    if ($customer->date == '2012-01-10')
    {
        echo $customer->cid . "<br>\n";
        echo $customer->amount_paid . "<br>\n";
    }
}
于 2013-02-08T06:26:21.653 に答える