Example #1
0
/**
 * Function: array_to_xml()
 * ref: http://stackoverflow.com/a/3289602 (onokazu)
 *
 * This function returns an xml format of an array
 * Usage: core_array_to_xml(ARRAY, SimpleXMLElement OBJECT)
 */
function core_array_to_xml($arr = array(), SimpleXMLElement $xml)
{
    foreach ($arr as $k => $v) {
        if (is_numeric($k)) {
            $k = 'item';
        }
        if (is_array($v)) {
            core_array_to_xml($v, $xml->addChild($k));
        } else {
            $xml->addChild($k, $v);
        }
    }
    return $xml;
}
Example #2
0
                exit;
            } else {
                // default error return
                $json['status'] = 'ERR';
                $json['error'] = '102';
            }
    }
}
// add an error_string to json response
$json['error_string'] = $ws_error_string[$json['error']];
// add timestamp
$json['timestamp'] = mktime();
if ($log_this) {
    logger_print("u:" . $u . " ip:" . $_SERVER['REMOTE_ADDR'] . " op:" . _OP_ . ' timestamp:' . $json['timestamp'] . ' status:' . $json['status'] . ' error:' . $json['error'] . ' error_string:' . $json['error_string'], 3, "webservices");
}
if ($format == 'SERIALIZE') {
    ob_end_clean();
    header('Content-Type: text/plain');
    _p(serialize($json));
} else {
    if ($format == 'XML') {
        $xml = core_array_to_xml($json, new SimpleXMLElement('<response/>'));
        ob_end_clean();
        header('Content-Type: text/xml');
        _p($xml->asXML());
    } else {
        ob_end_clean();
        header('Content-Type: application/json');
        _p(json_encode($json));
    }
}