2015-01-11 64 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