Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // multi/signel converter array to xml
- // example: https://imgur.com/a/LsQY8A7
- function printResponse($data)
- {
- $xml = new DOMDocument();
- $root = $xml->appendChild($xml->createElement('root'));
- $response = $root->appendChild($xml->createElement('response'));
- arrayToXml($xml, $response, $data);
- header("Content-Type: text/plain");
- $xml->formatOutput = true;
- die($xml->saveXml());
- }
- function arrayToXml($xml, $root, $data)
- {
- foreach($data as $key => $item)
- {
- if(is_array($item))
- arrayToXml($xml, $root->appendChild($xml->createElement($key)), $item);
- else
- $root->appendChild($xml->createElement($key, $item));
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement