Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('db.class.php');
- $connInfo = array('user' => '', 'pass' => '', 'host' => '', 'name' => '');
- $db = new Db($connInfo);
- function printResponse($status, $data)
- {
- $xmlDoc = new DOMDocument();
- $xmlDoc->encoding = 'UTF-8';
- $root = $xmlDoc->appendChild($xmlDoc->createElement('root'));
- $root->appendChild($xmlDoc->createElement('status', $status));
- $infoBl = $root->appendChild($xmlDoc->createElement('response'));
- foreach($data as $key => $val)
- $infoBl->appendChild($xmlDoc->createElement($key, $val));
- header("Content-Type: text/plain");
- $xmlDoc->formatOutput = true;
- die($xmlDoc->saveXml());
- }
- function printListResponse($status, $data, $itemTitle)
- {
- $xmlDoc = new DOMDocument();
- $root = $xmlDoc->appendChild($xmlDoc->createElement('root'));
- $root->appendChild($xmlDoc->createElement('status', $status));
- $items = $root->appendChild($xmlDoc->createElement('response'));
- foreach($data as $item)
- {
- $el = $items->appendChild($xmlDoc->createElement($itemTitle));
- foreach($item as $key => $val)
- $el->appendChild($xmlDoc->createElement($key, $val));
- }
- header("Content-Type: text/plain");
- $xmlDoc->formatOutput = true;
- die($xmlDoc->saveXml());
- }
- // example: https://imgur.com/a/qtsLMhE
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement