【发布时间】:2013-10-05 18:42:32
【问题描述】:
我正在尝试在 php 中使用 json 将 array 转换为 xml
json 和 array 工作正常,但是当我尝试将 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");
【问题讨论】:
-
你是在使用一些库还是没有名为
array_to_xml的内置php函数的东西 -
不是真的,我明白了。那么有没有办法让我完成这项工作?
-
你可以试试看this page他们使用DOM接口来创建xml