我想在PHP中使用json
JSON來Array對XML [PHP的]
的json
和array
做工精細轉換的array
到xml
但是當我嘗試轉換array
到xml
我不斷收到一個錯誤。
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");
你使用的是一些庫或沒有內建的php函數叫'array_to_xml' –
不是真的,我明白了。那麼有沒有辦法我可以做到這一點? – user2524169
你可以試着看[這個頁面](http://darklaunch.com/2009/05/23/php-xml-encode-using-domdocument-convert-array-to-xml-json-encode)他們使用DOM界面創建xml –