Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: class-json.php
<?php
[0] Fix | Delete
_deprecated_file( basename( __FILE__ ), '5.3.0', '', 'The PHP native JSON extension is now a requirement.' );
[1] Fix | Delete
[2] Fix | Delete
if ( ! class_exists( 'Services_JSON' ) ) :
[3] Fix | Delete
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
[4] Fix | Delete
/**
[5] Fix | Delete
* Converts to and from JSON format.
[6] Fix | Delete
*
[7] Fix | Delete
* JSON (JavaScript Object Notation) is a lightweight data-interchange
[8] Fix | Delete
* format. It is easy for humans to read and write. It is easy for machines
[9] Fix | Delete
* to parse and generate. It is based on a subset of the JavaScript
[10] Fix | Delete
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
[11] Fix | Delete
* This feature can also be found in Python. JSON is a text format that is
[12] Fix | Delete
* completely language independent but uses conventions that are familiar
[13] Fix | Delete
* to programmers of the C-family of languages, including C, C++, C#, Java,
[14] Fix | Delete
* JavaScript, Perl, TCL, and many others. These properties make JSON an
[15] Fix | Delete
* ideal data-interchange language.
[16] Fix | Delete
*
[17] Fix | Delete
* This package provides a simple encoder and decoder for JSON notation. It
[18] Fix | Delete
* is intended for use with client-side JavaScript applications that make
[19] Fix | Delete
* use of HTTPRequest to perform server communication functions - data can
[20] Fix | Delete
* be encoded into JSON notation for use in a client-side javaScript, or
[21] Fix | Delete
* decoded from incoming JavaScript requests. JSON format is native to
[22] Fix | Delete
* JavaScript, and can be directly eval()'ed with no further parsing
[23] Fix | Delete
* overhead
[24] Fix | Delete
*
[25] Fix | Delete
* All strings should be in ASCII or UTF-8 format!
[26] Fix | Delete
*
[27] Fix | Delete
* LICENSE: Redistribution and use in source and binary forms, with or
[28] Fix | Delete
* without modification, are permitted provided that the following
[29] Fix | Delete
* conditions are met: Redistributions of source code must retain the
[30] Fix | Delete
* above copyright notice, this list of conditions and the following
[31] Fix | Delete
* disclaimer. Redistributions in binary form must reproduce the above
[32] Fix | Delete
* copyright notice, this list of conditions and the following disclaimer
[33] Fix | Delete
* in the documentation and/or other materials provided with the
[34] Fix | Delete
* distribution.
[35] Fix | Delete
*
[36] Fix | Delete
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
[37] Fix | Delete
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
[38] Fix | Delete
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
[39] Fix | Delete
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
[40] Fix | Delete
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
[41] Fix | Delete
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
[42] Fix | Delete
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
[43] Fix | Delete
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
[44] Fix | Delete
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
[45] Fix | Delete
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
[46] Fix | Delete
* DAMAGE.
[47] Fix | Delete
*
[48] Fix | Delete
* @category
[49] Fix | Delete
* @package Services_JSON
[50] Fix | Delete
* @author Michal Migurski <mike-json@teczno.com>
[51] Fix | Delete
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
[52] Fix | Delete
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
[53] Fix | Delete
* @copyright 2005 Michal Migurski
[54] Fix | Delete
* @version CVS: $Id: JSON.php 305040 2010-11-02 23:19:03Z alan_k $
[55] Fix | Delete
* @license https://www.opensource.org/licenses/bsd-license.php
[56] Fix | Delete
* @link https://pear.php.net/pepr/pepr-proposal-show.php?id=198
[57] Fix | Delete
*/
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[61] Fix | Delete
*/
[62] Fix | Delete
define('SERVICES_JSON_SLICE', 1);
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[66] Fix | Delete
*/
[67] Fix | Delete
define('SERVICES_JSON_IN_STR', 2);
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[71] Fix | Delete
*/
[72] Fix | Delete
define('SERVICES_JSON_IN_ARR', 3);
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[76] Fix | Delete
*/
[77] Fix | Delete
define('SERVICES_JSON_IN_OBJ', 4);
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Marker constant for Services_JSON::decode(), used to flag stack state
[81] Fix | Delete
*/
[82] Fix | Delete
define('SERVICES_JSON_IN_CMT', 5);
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Behavior switch for Services_JSON::decode()
[86] Fix | Delete
*/
[87] Fix | Delete
define('SERVICES_JSON_LOOSE_TYPE', 16);
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Behavior switch for Services_JSON::decode()
[91] Fix | Delete
*/
[92] Fix | Delete
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Behavior switch for Services_JSON::decode()
[96] Fix | Delete
*/
[97] Fix | Delete
define('SERVICES_JSON_USE_TO_JSON', 64);
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Converts to and from JSON format.
[101] Fix | Delete
*
[102] Fix | Delete
* Brief example of use:
[103] Fix | Delete
*
[104] Fix | Delete
* <code>
[105] Fix | Delete
* // create a new instance of Services_JSON
[106] Fix | Delete
* $json = new Services_JSON();
[107] Fix | Delete
*
[108] Fix | Delete
* // convert a complex value to JSON notation, and send it to the browser
[109] Fix | Delete
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
[110] Fix | Delete
* $output = $json->encode($value);
[111] Fix | Delete
*
[112] Fix | Delete
* print($output);
[113] Fix | Delete
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
[114] Fix | Delete
*
[115] Fix | Delete
* // accept incoming POST data, assumed to be in JSON notation
[116] Fix | Delete
* $input = file_get_contents('php://input', 1000000);
[117] Fix | Delete
* $value = $json->decode($input);
[118] Fix | Delete
* </code>
[119] Fix | Delete
*/
[120] Fix | Delete
class Services_JSON
[121] Fix | Delete
{
[122] Fix | Delete
/**
[123] Fix | Delete
* Object behavior flags.
[124] Fix | Delete
*
[125] Fix | Delete
* @var int
[126] Fix | Delete
*/
[127] Fix | Delete
public $use;
[128] Fix | Delete
[129] Fix | Delete
// private - cache the mbstring lookup results..
[130] Fix | Delete
var $_mb_strlen = false;
[131] Fix | Delete
var $_mb_substr = false;
[132] Fix | Delete
var $_mb_convert_encoding = false;
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* constructs a new JSON instance
[136] Fix | Delete
*
[137] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[138] Fix | Delete
*
[139] Fix | Delete
* @param int $use object behavior flags; combine with boolean-OR
[140] Fix | Delete
*
[141] Fix | Delete
* possible values:
[142] Fix | Delete
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
[143] Fix | Delete
* "{...}" syntax creates associative arrays
[144] Fix | Delete
* instead of objects in decode().
[145] Fix | Delete
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
[146] Fix | Delete
* Values which can't be encoded (e.g. resources)
[147] Fix | Delete
* appear as NULL instead of throwing errors.
[148] Fix | Delete
* By default, a deeply-nested resource will
[149] Fix | Delete
* bubble up with an error, so all return values
[150] Fix | Delete
* from encode() should be checked with isError()
[151] Fix | Delete
* - SERVICES_JSON_USE_TO_JSON: call toJSON when serializing objects
[152] Fix | Delete
* It serializes the return value from the toJSON call rather
[153] Fix | Delete
* than the object itself, toJSON can return associative arrays,
[154] Fix | Delete
* strings or numbers, if you return an object, make sure it does
[155] Fix | Delete
* not have a toJSON method, otherwise an error will occur.
[156] Fix | Delete
*/
[157] Fix | Delete
function __construct( $use = 0 )
[158] Fix | Delete
{
[159] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[160] Fix | Delete
[161] Fix | Delete
$this->use = $use;
[162] Fix | Delete
$this->_mb_strlen = function_exists('mb_strlen');
[163] Fix | Delete
$this->_mb_convert_encoding = function_exists('mb_convert_encoding');
[164] Fix | Delete
$this->_mb_substr = function_exists('mb_substr');
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* PHP4 constructor.
[169] Fix | Delete
*
[170] Fix | Delete
* @deprecated 5.3.0 Use __construct() instead.
[171] Fix | Delete
*
[172] Fix | Delete
* @see Services_JSON::__construct()
[173] Fix | Delete
*/
[174] Fix | Delete
public function Services_JSON( $use = 0 ) {
[175] Fix | Delete
_deprecated_constructor( 'Services_JSON', '5.3.0', get_class( $this ) );
[176] Fix | Delete
self::__construct( $use );
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* convert a string from one UTF-16 char to one UTF-8 char
[181] Fix | Delete
*
[182] Fix | Delete
* Normally should be handled by mb_convert_encoding, but
[183] Fix | Delete
* provides a slower PHP-only method for installations
[184] Fix | Delete
* that lack the multibye string extension.
[185] Fix | Delete
*
[186] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[187] Fix | Delete
*
[188] Fix | Delete
* @param string $utf16 UTF-16 character
[189] Fix | Delete
* @return string UTF-8 character
[190] Fix | Delete
* @access private
[191] Fix | Delete
*/
[192] Fix | Delete
function utf162utf8($utf16)
[193] Fix | Delete
{
[194] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[195] Fix | Delete
[196] Fix | Delete
// oh please oh please oh please oh please oh please
[197] Fix | Delete
if($this->_mb_convert_encoding) {
[198] Fix | Delete
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
$bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
[202] Fix | Delete
[203] Fix | Delete
switch(true) {
[204] Fix | Delete
case ((0x7F & $bytes) == $bytes):
[205] Fix | Delete
// this case should never be reached, because we are in ASCII range
[206] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[207] Fix | Delete
return chr(0x7F & $bytes);
[208] Fix | Delete
[209] Fix | Delete
case (0x07FF & $bytes) == $bytes:
[210] Fix | Delete
// return a 2-byte UTF-8 character
[211] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[212] Fix | Delete
return chr(0xC0 | (($bytes >> 6) & 0x1F))
[213] Fix | Delete
. chr(0x80 | ($bytes & 0x3F));
[214] Fix | Delete
[215] Fix | Delete
case (0xFFFF & $bytes) == $bytes:
[216] Fix | Delete
// return a 3-byte UTF-8 character
[217] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[218] Fix | Delete
return chr(0xE0 | (($bytes >> 12) & 0x0F))
[219] Fix | Delete
. chr(0x80 | (($bytes >> 6) & 0x3F))
[220] Fix | Delete
. chr(0x80 | ($bytes & 0x3F));
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
// ignoring UTF-32 for now, sorry
[224] Fix | Delete
return '';
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* convert a string from one UTF-8 char to one UTF-16 char
[229] Fix | Delete
*
[230] Fix | Delete
* Normally should be handled by mb_convert_encoding, but
[231] Fix | Delete
* provides a slower PHP-only method for installations
[232] Fix | Delete
* that lack the multibyte string extension.
[233] Fix | Delete
*
[234] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[235] Fix | Delete
*
[236] Fix | Delete
* @param string $utf8 UTF-8 character
[237] Fix | Delete
* @return string UTF-16 character
[238] Fix | Delete
* @access private
[239] Fix | Delete
*/
[240] Fix | Delete
function utf82utf16($utf8)
[241] Fix | Delete
{
[242] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[243] Fix | Delete
[244] Fix | Delete
// oh please oh please oh please oh please oh please
[245] Fix | Delete
if($this->_mb_convert_encoding) {
[246] Fix | Delete
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
switch($this->strlen8($utf8)) {
[250] Fix | Delete
case 1:
[251] Fix | Delete
// this case should never be reached, because we are in ASCII range
[252] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[253] Fix | Delete
return $utf8;
[254] Fix | Delete
[255] Fix | Delete
case 2:
[256] Fix | Delete
// return a UTF-16 character from a 2-byte UTF-8 char
[257] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[258] Fix | Delete
return chr(0x07 & (ord($utf8[0]) >> 2))
[259] Fix | Delete
. chr((0xC0 & (ord($utf8[0]) << 6))
[260] Fix | Delete
| (0x3F & ord($utf8[1])));
[261] Fix | Delete
[262] Fix | Delete
case 3:
[263] Fix | Delete
// return a UTF-16 character from a 3-byte UTF-8 char
[264] Fix | Delete
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[265] Fix | Delete
return chr((0xF0 & (ord($utf8[0]) << 4))
[266] Fix | Delete
| (0x0F & (ord($utf8[1]) >> 2)))
[267] Fix | Delete
. chr((0xC0 & (ord($utf8[1]) << 6))
[268] Fix | Delete
| (0x7F & ord($utf8[2])));
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
// ignoring UTF-32 for now, sorry
[272] Fix | Delete
return '';
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* encodes an arbitrary variable into JSON format (and sends JSON Header)
[277] Fix | Delete
*
[278] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[279] Fix | Delete
*
[280] Fix | Delete
* @param mixed $var any number, boolean, string, array, or object to be encoded.
[281] Fix | Delete
* see argument 1 to Services_JSON() above for array-parsing behavior.
[282] Fix | Delete
* if var is a string, note that encode() always expects it
[283] Fix | Delete
* to be in ASCII or UTF-8 format!
[284] Fix | Delete
*
[285] Fix | Delete
* @return mixed JSON string representation of input var or an error if a problem occurs
[286] Fix | Delete
* @access public
[287] Fix | Delete
*/
[288] Fix | Delete
function encode($var)
[289] Fix | Delete
{
[290] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[291] Fix | Delete
[292] Fix | Delete
header('Content-Type: application/json');
[293] Fix | Delete
return $this->encodeUnsafe($var);
[294] Fix | Delete
}
[295] Fix | Delete
/**
[296] Fix | Delete
* encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!!)
[297] Fix | Delete
*
[298] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[299] Fix | Delete
*
[300] Fix | Delete
* @param mixed $var any number, boolean, string, array, or object to be encoded.
[301] Fix | Delete
* see argument 1 to Services_JSON() above for array-parsing behavior.
[302] Fix | Delete
* if var is a string, note that encode() always expects it
[303] Fix | Delete
* to be in ASCII or UTF-8 format!
[304] Fix | Delete
*
[305] Fix | Delete
* @return mixed JSON string representation of input var or an error if a problem occurs
[306] Fix | Delete
* @access public
[307] Fix | Delete
*/
[308] Fix | Delete
function encodeUnsafe($var)
[309] Fix | Delete
{
[310] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[311] Fix | Delete
[312] Fix | Delete
// see bug #16908 - regarding numeric locale printing
[313] Fix | Delete
$lc = setlocale(LC_NUMERIC, 0);
[314] Fix | Delete
setlocale(LC_NUMERIC, 'C');
[315] Fix | Delete
$ret = $this->_encode($var);
[316] Fix | Delete
setlocale(LC_NUMERIC, $lc);
[317] Fix | Delete
return $ret;
[318] Fix | Delete
[319] Fix | Delete
}
[320] Fix | Delete
/**
[321] Fix | Delete
* PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format
[322] Fix | Delete
*
[323] Fix | Delete
* @deprecated 5.3.0 Use the PHP native JSON extension instead.
[324] Fix | Delete
*
[325] Fix | Delete
* @param mixed $var any number, boolean, string, array, or object to be encoded.
[326] Fix | Delete
* see argument 1 to Services_JSON() above for array-parsing behavior.
[327] Fix | Delete
* if var is a string, note that encode() always expects it
[328] Fix | Delete
* to be in ASCII or UTF-8 format!
[329] Fix | Delete
*
[330] Fix | Delete
* @return mixed JSON string representation of input var or an error if a problem occurs
[331] Fix | Delete
* @access public
[332] Fix | Delete
*/
[333] Fix | Delete
function _encode($var)
[334] Fix | Delete
{
[335] Fix | Delete
_deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
[336] Fix | Delete
[337] Fix | Delete
switch (gettype($var)) {
[338] Fix | Delete
case 'boolean':
[339] Fix | Delete
return $var ? 'true' : 'false';
[340] Fix | Delete
[341] Fix | Delete
case 'NULL':
[342] Fix | Delete
return 'null';
[343] Fix | Delete
[344] Fix | Delete
case 'integer':
[345] Fix | Delete
return (int) $var;
[346] Fix | Delete
[347] Fix | Delete
case 'double':
[348] Fix | Delete
case 'float':
[349] Fix | Delete
return (float) $var;
[350] Fix | Delete
[351] Fix | Delete
case 'string':
[352] Fix | Delete
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
[353] Fix | Delete
$ascii = '';
[354] Fix | Delete
$strlen_var = $this->strlen8($var);
[355] Fix | Delete
[356] Fix | Delete
/*
[357] Fix | Delete
* Iterate over every character in the string,
[358] Fix | Delete
* escaping with a slash or encoding to UTF-8 where necessary
[359] Fix | Delete
*/
[360] Fix | Delete
for ($c = 0; $c < $strlen_var; ++$c) {
[361] Fix | Delete
[362] Fix | Delete
$ord_var_c = ord($var[$c]);
[363] Fix | Delete
[364] Fix | Delete
switch (true) {
[365] Fix | Delete
case $ord_var_c == 0x08:
[366] Fix | Delete
$ascii .= '\b';
[367] Fix | Delete
break;
[368] Fix | Delete
case $ord_var_c == 0x09:
[369] Fix | Delete
$ascii .= '\t';
[370] Fix | Delete
break;
[371] Fix | Delete
case $ord_var_c == 0x0A:
[372] Fix | Delete
$ascii .= '\n';
[373] Fix | Delete
break;
[374] Fix | Delete
case $ord_var_c == 0x0C:
[375] Fix | Delete
$ascii .= '\f';
[376] Fix | Delete
break;
[377] Fix | Delete
case $ord_var_c == 0x0D:
[378] Fix | Delete
$ascii .= '\r';
[379] Fix | Delete
break;
[380] Fix | Delete
[381] Fix | Delete
case $ord_var_c == 0x22:
[382] Fix | Delete
case $ord_var_c == 0x2F:
[383] Fix | Delete
case $ord_var_c == 0x5C:
[384] Fix | Delete
// double quote, slash, slosh
[385] Fix | Delete
$ascii .= '\\'.$var[$c];
[386] Fix | Delete
break;
[387] Fix | Delete
[388] Fix | Delete
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
[389] Fix | Delete
// characters U-00000000 - U-0000007F (same as ASCII)
[390] Fix | Delete
$ascii .= $var[$c];
[391] Fix | Delete
break;
[392] Fix | Delete
[393] Fix | Delete
case (($ord_var_c & 0xE0) == 0xC0):
[394] Fix | Delete
// characters U-00000080 - U-000007FF, mask 110XXXXX
[395] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[396] Fix | Delete
if ($c+1 >= $strlen_var) {
[397] Fix | Delete
$c += 1;
[398] Fix | Delete
$ascii .= '?';
[399] Fix | Delete
break;
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
$char = pack('C*', $ord_var_c, ord($var[$c + 1]));
[403] Fix | Delete
$c += 1;
[404] Fix | Delete
$utf16 = $this->utf82utf16($char);
[405] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[406] Fix | Delete
break;
[407] Fix | Delete
[408] Fix | Delete
case (($ord_var_c & 0xF0) == 0xE0):
[409] Fix | Delete
if ($c+2 >= $strlen_var) {
[410] Fix | Delete
$c += 2;
[411] Fix | Delete
$ascii .= '?';
[412] Fix | Delete
break;
[413] Fix | Delete
}
[414] Fix | Delete
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
[415] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[416] Fix | Delete
$char = pack('C*', $ord_var_c,
[417] Fix | Delete
@ord($var[$c + 1]),
[418] Fix | Delete
@ord($var[$c + 2]));
[419] Fix | Delete
$c += 2;
[420] Fix | Delete
$utf16 = $this->utf82utf16($char);
[421] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[422] Fix | Delete
break;
[423] Fix | Delete
[424] Fix | Delete
case (($ord_var_c & 0xF8) == 0xF0):
[425] Fix | Delete
if ($c+3 >= $strlen_var) {
[426] Fix | Delete
$c += 3;
[427] Fix | Delete
$ascii .= '?';
[428] Fix | Delete
break;
[429] Fix | Delete
}
[430] Fix | Delete
// characters U-00010000 - U-001FFFFF, mask 11110XXX
[431] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[432] Fix | Delete
$char = pack('C*', $ord_var_c,
[433] Fix | Delete
ord($var[$c + 1]),
[434] Fix | Delete
ord($var[$c + 2]),
[435] Fix | Delete
ord($var[$c + 3]));
[436] Fix | Delete
$c += 3;
[437] Fix | Delete
$utf16 = $this->utf82utf16($char);
[438] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[439] Fix | Delete
break;
[440] Fix | Delete
[441] Fix | Delete
case (($ord_var_c & 0xFC) == 0xF8):
[442] Fix | Delete
// characters U-00200000 - U-03FFFFFF, mask 111110XX
[443] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[444] Fix | Delete
if ($c+4 >= $strlen_var) {
[445] Fix | Delete
$c += 4;
[446] Fix | Delete
$ascii .= '?';
[447] Fix | Delete
break;
[448] Fix | Delete
}
[449] Fix | Delete
$char = pack('C*', $ord_var_c,
[450] Fix | Delete
ord($var[$c + 1]),
[451] Fix | Delete
ord($var[$c + 2]),
[452] Fix | Delete
ord($var[$c + 3]),
[453] Fix | Delete
ord($var[$c + 4]));
[454] Fix | Delete
$c += 4;
[455] Fix | Delete
$utf16 = $this->utf82utf16($char);
[456] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[457] Fix | Delete
break;
[458] Fix | Delete
[459] Fix | Delete
case (($ord_var_c & 0xFE) == 0xFC):
[460] Fix | Delete
if ($c+5 >= $strlen_var) {
[461] Fix | Delete
$c += 5;
[462] Fix | Delete
$ascii .= '?';
[463] Fix | Delete
break;
[464] Fix | Delete
}
[465] Fix | Delete
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
[466] Fix | Delete
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
[467] Fix | Delete
$char = pack('C*', $ord_var_c,
[468] Fix | Delete
ord($var[$c + 1]),
[469] Fix | Delete
ord($var[$c + 2]),
[470] Fix | Delete
ord($var[$c + 3]),
[471] Fix | Delete
ord($var[$c + 4]),
[472] Fix | Delete
ord($var[$c + 5]));
[473] Fix | Delete
$c += 5;
[474] Fix | Delete
$utf16 = $this->utf82utf16($char);
[475] Fix | Delete
$ascii .= sprintf('\u%04s', bin2hex($utf16));
[476] Fix | Delete
break;
[477] Fix | Delete
}
[478] Fix | Delete
}
[479] Fix | Delete
return '"'.$ascii.'"';
[480] Fix | Delete
[481] Fix | Delete
case 'array':
[482] Fix | Delete
/*
[483] Fix | Delete
* As per JSON spec if any array key is not an integer
[484] Fix | Delete
* we must treat the whole array as an object. We
[485] Fix | Delete
* also try to catch a sparsely populated associative
[486] Fix | Delete
* array with numeric keys here because some JS engines
[487] Fix | Delete
* will create an array with empty indexes up to
[488] Fix | Delete
* max_index which can cause memory issues and because
[489] Fix | Delete
* the keys, which may be relevant, will be remapped
[490] Fix | Delete
* otherwise.
[491] Fix | Delete
*
[492] Fix | Delete
* As per the ECMA and JSON specification an object may
[493] Fix | Delete
* have any string as a property. Unfortunately due to
[494] Fix | Delete
* a hole in the ECMA specification if the key is a
[495] Fix | Delete
* ECMA reserved word or starts with a digit the
[496] Fix | Delete
* parameter is only accessible using ECMAScript's
[497] Fix | Delete
* bracket notation.
[498] Fix | Delete
*/
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function