繁体   English   中英

使用php按日期过滤xml数据

[英]Filter xml data by date using php

我想使用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? 例如。 我想获得日期=“ 2012-01-10”的客户

实际观看

<?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";
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM