Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created November 13, 2010 20:38
Show Gist options
  • Save guilleiguaran/675621 to your computer and use it in GitHub Desktop.
Save guilleiguaran/675621 to your computer and use it in GitHub Desktop.
<?php
/* Parse a SQL row array to XML document
Usage Example:
...
$row = mysql_fetch_array($result);
$xml = sql_array_to_xml($row, "contacto");
header('Content-Type: text/xml')
echo $xml;
*/
function sql_array_to_xml($sql_array, $root)
{
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xml .= '<'.$root.'>';
foreach($sql_array as $key => $value)
{
$xml .= '<'.$key.'>'.$value.'</'.$key.'>';
}
$xml .= '</'.$root.'>';
return $xml;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment