Last active
September 20, 2016 13:57
-
-
Save phaberest/763a14a9b15fbb6711addd40a15d668b to your computer and use it in GitHub Desktop.
Revisions
-
phaberest renamed this gist
Sep 20, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
phaberest created this gist
Sep 20, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ private function arrayToXML($data, &$xml) { foreach ($data as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { $key = 'item'.$key; //dealing with <0/>..<n/> issues } $subnode = $xml->addChild($key); array_to_xml($value, $subnode); } else { $xml->addChild("$key", htmlspecialchars("$value")); } } } private function prepareXML(array $array) { $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); $this->array_to_xml($data, $xml); return $xml; # Get XML with $->asXML(), save it with $->asXML({path}) }