/** * xml_from_array * This takes a one dimensional array and * creates a XML document form it for use * primarly by the ajax mojo */ function xml_from_array($array,$callback=0,$type='') { if (empty($type)){ foreach ($array as $key=>$value) { if (is_numeric($key)) { $key = 'item'; } if (is_array($value)) { $value = xml_from_array($value,1); $string .= "\t$value\n"; } else { /* We need to escape the value */ $string .= "\t\n"; } } // end foreach elements } elseif ($type == "itunesdb"){ foreach ($array as $key=>$value) { if (is_array($value)) { $value = xml_from_array($value,1,$type); $string .= "\t<$key>\n$value\t\n"; } else { if (is_numeric($value)) { $string .= "\t\t<$key>$value\n"; } else { /* We need to escape the value */ $string .= "\t\t<$key>\n"; } } } } if (!$callback) { $string = "\n\n" . $string . "\n"; } return $string; } // xml_from_array