2013-02-26 46 views
2
<?php 
$picid= $_GET['id']; 
intval($picid); 
$file="data.xml"; 
echo $picid; //output is 121 (say) 
$data= new SimpleXMLElement($file, null, true); 
$data->score[$picid]=$data->score[$picid]+3; 
file_put_contents($file, $data->asXML()); 
?> 

中的XML文件的變化來編輯XML文件的內容,以無法在PHP

<score 121="3">0</score> 

所述分數[0]標籤。

而我要上得分[121]標記輸出

<score>3</score> 

但是,當我在我的代碼更改

<?php 
$picid= $_GET['id']; 
intval($picid); 
$file="data.xml"; 
echo $picid; //121 is printed (say) 
$data= new SimpleXMLElement($file, null, true); 
$data->score[121]=$data->score[121]+3; 
echo $data->score[121]; 
file_put_contents($file, $data->asXML()); 
?> 

我正在gettng所需的輸出。爲什麼?

回答

2

你的intval返回void。

嘗試:

$picid = intval($picid); 
+0

哦,親愛的,這樣一個愚蠢的錯誤,。謝謝,它工作。 :) – 2013-02-26 23:19:02

+0

不客氣) – apoq 2013-02-26 23:37:35