Ejemplo n.º 1
0
function xoutput_from_array($array, $callback = false, $type = '')
{
    $output = isset($_REQUEST['xoutput']) ? $_REQUEST['xoutput'] : 'xml';
    if ($output == 'xml') {
        return xml_from_array($array, $callback, $type);
    } elseif ($output == 'raw') {
        $outputnode = $_REQUEST['xoutputnode'];
        return $array[$outputnode];
    } else {
        return json_from_array($array, $callback, $type);
    }
}
Ejemplo n.º 2
0
function xml_from_array($array, $num_prefix = 'num_', $item_name = 'item')
{
    if (!$item_name) {
        $item_name = 'item';
    }
    if (!is_array($array)) {
        $result = xml_cdata($array);
        return $result;
    } else {
        $result = '';
        foreach ($array as $key => $val) {
            $attrs = array();
            if (is_numeric($key)) {
                if ($num_prefix) {
                    $key = $num_prefix . $key;
                } else {
                    $attrs['num'] = $key;
                    $key = $item_name;
                }
            } elseif ('' == $key) {
                $key = $item_name;
            }
            $key = preg_replace('/\\s+/', '_', $key);
            $result .= xml_element($key, $attrs, xml_from_array($val, $num_prefix, $item_name));
        }
        return $result;
    }
}