示例#1
0
function _getEncodedVal($val, $is_sub_set = false)
{
    if (preg_match('/^\\<\\!\\[CDATA\\[/', $val)) {
        $buff = sprintf("<value>%s</value>", $val);
    } elseif (is_int($val)) {
        $buff = sprintf("<value><i4>%d</i4></value>", $val);
    } elseif (is_string($val) && preg_match('/^([0-9]+)T([0-9\\:]+)$/', $val)) {
        $buff = sprintf("<value><dateTime.iso8601>%s</dateTime.iso8601></value>\n", $val);
    } elseif (is_double($val)) {
        $buff = sprintf("<value><double>%f</double></value>", $val);
    } elseif (is_bool($val)) {
        $buff = sprintf("<value><boolean>%d</boolean></value>", $val ? 1 : 0);
    } elseif (is_object($val)) {
        $values = get_object_vars($val);
        $val_count = count($values);
        $buff = "<value><struct>";
        foreach ($values as $k => $v) {
            $buff .= sprintf("<member>\n<name>%s</name>\n%s</member>\n", htmlspecialchars($k, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), _getEncodedVal($v, true));
        }
        $buff .= "</struct></value>\n";
    } elseif (is_array($val)) {
        $val_count = count($val);
        $buff = "<value><array>\n<data>";
        for ($i = 0; $i < $val_count; $i++) {
            $buff .= _getEncodedVal($val[$i], true);
        }
        $buff .= "</data>\n</array></value>";
    } else {
        $buff = sprintf("<value><string>%s</string></value>\n", $val);
    }
    if (!$is_sub_set) {
        return sprintf("<param>\n%s</param>", $buff);
    }
    return $buff;
}
示例#2
0
function _getEncodedVal($val, $is_sub_set = false)
{
    if (is_int($val)) {
        $buff = sprintf("<value><i4>%d</i4></value>", $val);
    } elseif (is_double($val)) {
        $buff = sprintf("<value><double>%f</double></value>", $val);
    } elseif (is_bool($val)) {
        $buff = sprintf("<value><boolean>%d</boolean></value>", $val ? 1 : 0);
    } elseif (is_object($val)) {
        $values = get_object_vars($val);
        $val_count = count($values);
        $buff = "<value><struct>";
        foreach ($values as $k => $v) {
            $buff .= sprintf("<member>\n<name>%s</name>\n%s</member>\n", htmlspecialchars($k), _getEncodedVal($v, true));
        }
        $buff .= "</struct></value>\n";
    } elseif (is_array($val)) {
        $val_count = count($val);
        $buff = "<value><array>\n<data>";
        for ($i = 0; $i < $val_count; $i++) {
            $buff .= _getEncodedVal($val[$i], true);
        }
        $buff .= "</data>\n</array></value>";
    } else {
        $buff = sprintf("<value><string>%s</string></value>\n", $val);
    }
    if (!$is_sub_set) {
        return sprintf("<param>\n%s</param>", $buff);
    }
    return $buff;
}