Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $query = "SELECT * from table";
- $result = $con->query($query);
- WHILE($row = $result->fetch_assoc()) {
- $data[] = $row;
- }
- function array_to_xml( $data, &$xml_data ) {
- foreach( $data as $key => $value ) {
- if( is_numeric($key) ){
- $key = 'item'.$key; //dealing with <0/>..<n/> issues
- }
- if( is_array($value) ) {
- $subnode = $xml_data->addChild($key);
- array_to_xml($value, $subnode);
- } else {
- $xml_data->addChild("$key",htmlspecialchars("$value"));
- }
- }
- }
- $xml_data = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
- array_to_xml($array,$xml_data);
- $result = $xml_data->asXML('test.xml');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement