我試圖熟悉PHP SimpleXML
函數,並希望有一點幫助。我正在將更新提供給呼叫中心收到的呼叫,並且僅將新接收的呼叫從當前日期添加到組合字符串。我需要通過cronjob每10分鐘運行一次,並讓組合字符串在一天內增長。PHP SimpleXML添加兩個字符串,如果它們不包含
這裏是XML
I'm有工作:
<?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>
我想要做的是提取了foreach
循環中的所有phoneNumber
和time
元素,並將它們作爲一個字符串添加到組合逗號分離的字符串。
的字符串將看起來像這樣:
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
是從當前日期開始。
這裏是我有什麼,但it's不太多,我不確定這是否是做什麼,我想最好的辦法:
$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;
}
}
}
以上的回報一個空白頁,沒有錯誤。
您正在嘗試調試在同一時間的一切。爲什麼不首先測試循環是否正確地遍歷XML?即使是一個簡單的「回聲」也能解決問題。 –
謝謝'ÁlvaroG. Vicario'。我一直在使用'echo'和'die'來測試。 –