Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json到数组到XML[Php]_Php_Xml_Json - Fatal编程技术网

Json到数组到XML[Php]

Json到数组到XML[Php],php,xml,json,Php,Xml,Json,我试图在php中使用json将数组转换为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_decod

我试图在php中使用
json
数组转换为
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");
simplexml\u load\u字符串(数组到xml($json,新的simplexmlement(“”))->asXML())或die(“无法读取”);

可能是因为没有名为array_to_xml()的函数?你必须先定义它。

它应该是一个评论,真的。对不起,声誉不够。不管怎样,我还是想帮你。你是在使用库还是其他什么东西吗?没有内置的php函数名为
array\u to\u xml
,我明白了。那么,有没有一种方法可以实现这一点呢?你可以试着看看他们使用DOM接口来创建xml