note 101949 added to book.simplexml
| From: | philatdierdotus at osu1 dot php dot net | Date: | Wed, 19 Jan 2011 19:37:11 +0000 |
| Subject: | note 101949 added to book.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175908@lists.php.net to get a copy of this message | ||
Here's a function I came up with to convert an associative array to XML. Works for
multidimensional arrays as well.
function assocArrayToXML($root_element_name,$ar)
{
$xml = new SimpleXMLElement("<?xml
version=\"1.0\"?><{$root_element_name}></{$root_element_name}>");
$f = create_function('$f,$c,$a','
foreach($a as $k=>$v) {
if(is_array($v)) {
$ch=$c->addChild($k);
$f($f,$ch,$v);
} else {
$c->addChild($k,$v);
}
}');
$f($f,$xml,$ar);
return $xml->asXML();
}
----
Server IP: 192.41.42.26
Probable Submitter: 75.145.54.114
----
Manual Page -- http://www.php.net/manual/en/book.simplexml.php
Edit -- https://master.php.net/note/edit/101949
Del: integrated -- https://master.php.net/note/delete/101949/integrated
Del: useless -- https://master.php.net/note/delete/101949/useless
Del: bad code -- https://master.php.net/note/delete/101949/bad+code
Del: spam -- https://master.php.net/note/delete/101949/spam
Del: non-english -- https://master.php.net/note/delete/101949/non-english
Del: in docs -- https://master.php.net/note/delete/101949/in+docs
Del: other reasons-- https://master.php.net/note/delete/101949
Reject -- https://master.php.net/note/reject/101949
Search -- https://master.php.net/manage/user-notes.php