0

我正在尝试熟悉 PHPSimpleXML函数,希望能得到一些帮助。我正在获取呼叫中心接听电话的更新,并将当前日期的新接听电话添加到组合字符串中。我需要通过 cronjob 每 10 分钟运行一次,让组合字符串在一天中增长。

这是XML我正在使用的:

<?xml version="1.0" encoding="ISO-8859-1"?>
<received>
  <call>
    <countryCode>46</countryCode>
    <phoneNumber>4386541313</phoneNumber>
    <name>Unavailable</name>
    <time>2012-12-05T08:41:29.863Z</time>
  </call>
  ...
</received>


我想做的是用循环提取所有元素phoneNumber并将它们作为字符串添加到组合的逗号分隔字符串中。timeforeach

字符串如下所示:

From the above xml example 4386541313-2012-12-05T08:41:29.863Z
Or phoneNumber-time


逗号分隔的字符串如下所示:

4386541313-2012-12-05T08:41:29.863Z,1186111311-2012-12-03T08:11:21.561Z,...


我只想将字符串添加到当前日期的逗号分隔列表IF中。timestamp

这是我所拥有的,但并不多,我不确定这是否是做我想做的最好的方法:

$date_today = date('Y-m-d');
$combined_string = "4386541313-2012-12-05T08:41:29.863Z,1186111311-2012-12-03T08:11:21.561Z";

$received = simplexml_load_file('thexmlfile.xml');

foreach ($received->call->phoneNumber as $phoneNumber) { 
    foreach ($received->call->time as $time) {

        $new_call = $phoneNumber."-".$time;

        if(strpos($new_call,$date_today) !== false)
                    {
            $combined_string = $new_call.",".$combined_string;
        } 
    }
}

以上返回一个没有错误的空白页。

4

1 回答 1

1

可能想尝试类似的东西:

foreach ($received->call as $call) { 
    $new_call = $call->phoneNumber . "-" . $call->time;
    if(strpos($new_call,$date_today) !== false) {
        $combined_string = $new_call.",".$combined_string;
    } 
}

于 2012-12-05T12:19:17.217 回答