2015-01-11 68 views
0

我有一個php代碼的問題。 此代碼在Linux中運行平穩,但在Windows 7中無法運行。有什麼建議嗎?PHP代碼在Windows 7中無法正常工作apache(localhost)

$xml = simplexml_load_file('data.xml'); 
if(isset($_POST['confirmOrd'])){ 
     foreach($xml->xpath("orders/order[@id='".$_POST['confirmOrd']."']") as $change){ 
      $change->check = date('d/m/Y'); 
     } 
     $xml->asXML('data.xml'); 
} 

在windows Apache服務器我得到錯誤:

警告:主()[function.main]:不能分配給節點陣列(複製子節點或ATTR檢測)

+0

什麼是你的PHP版本? –

+0

這不是一個錯誤,只是一個警告。你可以通過使用error_reporting(E_ALL&〜E_WARNING)來抑制它。在你的程序中。 –

+0

你確定你沒有在linux上得到任何警告嗎?你檢查了日誌嗎? –

回答

0

試試這個。

$source = '<orders><order id="1"> <userid>Petros Petrou</userid> <date>04/01/2015</date> <check>0</check> <store>1</store> <product> <code>45887952</code> <quantity>1</quantity> </product> <product> <code>45887954</code> <quantity>1</quantity> </product> </order></orders>'; 

$xml = simplexml_load_string($source); 

$xpath = $xml->xpath("/orders/order[@id='1']"); 
if ($xpath!=false){ 
    foreach ($xpath as $change){ 
      $change->check = date('d/m/Y'); 
    } 
} 
var_dump($xpath); 
var_dump($xml); 

它工作正常,我

我可能是錯的。但只是嘗試:-)

+0

不可以。不工作 – GiorgosK

+0

您能否提供您嘗試使用的data.xml數據示例? – Alex

+0

'<訂單ID = 「1」> \t \t 佩特羅斯彼得魯 \t \t 2015年4月1日 \t \t \t \t \t \t \t \t \t 45887952 \t \t \t \t \t \t \t \t \t \t 45887954 \t \t \t \t \t \t' – GiorgosK