xml_to_array
来源:互联网 发布:windows正版系统 编辑:程序博客网 时间:2024/06/05 05:57
<?phpfunction arrtoxml($arr, $node = 'root'){ if ($node == 'root') { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><root></root>'); } else { $xml = $node; } foreach ($arr as $key => $value) { if (!is_array($value)) { $xml->addChild(is_string($key) ? $key : 'item', $value); } else { arrtoxml($value, $xml->addChild($key)); //创建节点 并加在他的后面 } } $xml->asXML('arrtoxml.xml'); return $xml->asXML();}$res = array( 'hello' => '11212', 'world' => '曹姐', 'array' => array( 'test' => 'test', 'b' => array('c' => 'c', 'd' => 'd') ), 'a' => 'haha', 'jie', 'yamin');echo arrtoxml($res);echo json_encode(simplexml_load_string(arrtoxml($res)), JSON_UNESCAPED_UNICODE);$xml = simplexml_load_file('arrtoxml.xml');var_dump(json_decode(json_encode($xml, JSON_UNESCAPED_UNICODE), true));
0 0