I´m trying to get familiar with the PHP SimpleXML function and would appreciate a little help. I´m fetching updates to a Call Center received calls and adding only new received calls from the current date to a combined string. I need to run this every 10 minutes via cronjob and let the combined string grow over the day.
Here is the XML I´m working with:
<?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>
What I would like to do is extract all phoneNumber and time elements with a foreach loop and add them as a string to a combined comma seperated string.
The string would looks like this:
From the above xml example 4386541313-2012-12-05T08:41:29.863Z
Or phoneNumber-time
The comma seperated string would look like this:
4386541313-2012-12-05T08:41:29.863Z,1186111311-2012-12-03T08:11:21.561Z,...
But I only want to add the string to the comma seperated list IF the timestamp is from the current date.
Here is what I have, but it´s not much and I´m not sure if this is the best way to do what I want:
$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;
}
}
}
The above returns a blank page with no errors.
Might want to try something like: