function array_to_XML($data, $rootNodeName = 'results', $xml=NULL){
if ($xml == null){
$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
}
foreach($data as $key => $value){
if (is_numeric($key)){
$key = "nodeId_". (string) $key;
}
if (is_array($value)){
$node = $xml->addChild($key);
array_to_XML($value, $rootNodeName, $node);
} else {
$value = htmlentities($value);
$xml->addChild($key, $value);
}
}
return html_entity_decode($xml->asXML());
}
No hay comentarios:
Publicar un comentario