2013-10-05 45 views
0

我想在PHP中使用jsonJSON來Array對XML [PHP的]

jsonarray做工精細轉換的arrayxml但是當我嘗試轉換arrayxml我不斷收到一個錯誤。

Call to undefined function array_to_xml() 

這是JSON

{"host":"127.0.0.1","username":"root","password":"something","dbname":"something","table":"something"} 

JSON來`陣列

$json = json_decode(file_get_contents('something.json'), true); 
$info = array(
$json['host'], 
$json['username'], 
$json['password'], 
$json['dbname'], 
);  

陣列爲xml

simplexml_load_string(array_to_xml($json, new SimpleXMLElement('<connection/>'))->asXML()) or die("can't read"); 
+1

你使用的是一些庫或沒有內建的php函數叫'array_to_xml' –

+0

不是真的,我明白了。那麼有沒有辦法我可以做到這一點? – user2524169

+1

你可以試着看[這個頁面](http://darklaunch.com/2009/05/23/php-xml-encode-using-domdocument-convert-array-to-xml-json-encode)他們使用DOM界面創建xml –

回答

0

也許是因爲沒有稱爲array_to_xml函數()?你必須先定義它。

+1

它應該是一個評論,真的。 –

+0

對不起,沒有足夠的聲望。反正我想幫忙。 – Anon