本文整理汇总了PHP中Services_JSON::utf82utf16方法的典型用法代码示例。如果您正苦于以下问题:PHP Services_JSON::utf82utf16方法的具体用法?PHP Services_JSON::utf82utf16怎么用?PHP Services_JSON::utf82utf16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Services_JSON
的用法示例。
在下文中一共展示了Services_JSON::utf82utf16方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: strlen
/**
* Convertstring as json_endcode
*/
function convert_string_non_latin($var)
{
require_once JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php';
$json = new Services_JSON();
$strlen_var = strlen($var);
$ascii = '';
for ($c = 0; $c < $strlen_var; ++$c) {
$ord_var_c = ord($var[$c]);
switch (true) {
case $ord_var_c == 0x8:
$ascii .= '\\b';
break;
case $ord_var_c == 0x9:
$ascii .= '\\t';
break;
case $ord_var_c == 0xa:
$ascii .= '\\n';
break;
case $ord_var_c == 0xc:
$ascii .= '\\f';
break;
case $ord_var_c == 0xd:
$ascii .= '\\r';
break;
case $ord_var_c == 0x22:
case $ord_var_c == 0x2f:
case $ord_var_c == 0x5c:
// double quote, slash, slosh
$ascii .= '\\' . $var[$c];
break;
case $ord_var_c >= 0x20 && $ord_var_c <= 0x7f:
// characters U-00000000 - U-0000007F (same as ASCII)
$ascii .= $var[$c];
break;
case ($ord_var_c & 0xe0) == 0xc0:
// characters U-00000080 - U-000007FF, mask 110XXXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var[$c + 1]));
$c += 1;
$utf16 = $json->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xf0) == 0xe0:
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]));
$c += 2;
$utf16 = $json->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xf8) == 0xf0:
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]));
$c += 3;
$utf16 = $json->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xfc) == 0xf8:
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]));
$c += 4;
$utf16 = $json->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
case ($ord_var_c & 0xfe) == 0xfc:
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5]));
$c += 5;
$utf16 = $json->utf82utf16($char);
$ascii .= sprintf('\\u%04s', bin2hex($utf16));
break;
}
}
return $ascii;
}