@ 2013-07-08T18:34:45Z <?php
if (!function_exists('json_encode')) {
function json_encode($it) {
if (!($assoc = is_object($it)) && !is_array($it)) {
return _js_enc_value($it);
}
$i = 0;
$it = (array)$it;
if (!$assoc) {
foreach ($it as $k => $v) {
if ($k !== $i) {
$assoc = true;
break;
}
$i++;
}
}
$data = array();
foreach ($it as $k => $v) {
$v = _js_enc_value($v);
if ($assoc) {
$k = _js_enc_value($k);
$data[] = $k . ':' . $v;
} else {
$data[] = $v;
}
}
if ($assoc) {
$bl = '{';
$br = '}';
} else {
$bl = '[';
$br = ']';
}
return $bl . implode(',', $data) . $br;
}
function _js_enc_value($value) {
switch (true) {
case is_array($value):
case is_object($value):
return json_encode($value);
case is_bool($value):
return $value ? 'true' : 'false';
case $value === null:
case is_resource($value) && _js_error():
return 'null';
case is_string($value):
return '"' . _js_uc_esc($value) . '"';
default:
return $value;
}
}
function _js_error() {
return trigger_error(
'json_encode(): type is unsupported, encoded as null',
E_USER_WARNING
);
}
function _js_uc_esc($value) {
$pattern = "@[\x08-x010\x0c\x0d\\\\\"/]|([ -!#-&(-.])++@";
return preg_replace_callback($pattern, '_js_uc_esc_cb', $value);
}
function _js_uc_esc_cb($matches) {
switch (true) {
case isset($matches[1]):
$char = mb_convert_encoding($matches[0], 'UTF-16', 'UTF-8');
$str = '';
$len = strlen($char);
for ($i = 0; $i < $len; $i += 2) {
$str .= sprintf('\\u%02x%02x',
ord($char[$i]),
ord($char[$i + 1])
);
}
return $str;
default:
return addcslashes($matches[0], "\x08\x09\x10\x0c\x0d\\\"/");
}
}
}
$str = '';
for ($i=0;$i<=32;$i++) {
$str .= chr($i);
}
$str = chr(127);
var_dump(json_encode("\xc0\x80" => "hoge"));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.17 0.013 0.040 12.41 5.4.16 0.012 0.042 12.40 5.4.15 0.013 0.042 12.40 5.4.14 0.013 0.053 12.09 5.4.13 0.015 0.040 12.07 5.4.12 0.013 0.041 12.04 5.4.11 0.011 0.043 12.03 5.4.10 0.015 0.052 12.04 5.4.9 0.017 0.059 12.03 5.4.8 0.015 0.040 12.03 5.4.7 0.012 0.041 12.03 5.4.6 0.012 0.040 12.03 5.4.5 0.013 0.042 12.03 5.4.4 0.020 0.053 12.02 5.4.3 0.013 0.041 12.01 5.4.2 0.012 0.042 12.01 5.4.1 0.013 0.039 12.01 5.4.0 0.011 0.042 11.50 5.3.26 0.013 0.044 12.72 5.3.25 0.012 0.046 12.72 5.3.24 0.015 0.043 12.72 5.3.23 0.023 0.056 12.71 5.3.22 0.014 0.043 12.68 5.3.21 0.013 0.047 12.68 5.3.20 0.014 0.045 12.68 5.3.19 0.028 0.073 12.68 5.3.18 0.012 0.048 12.67 5.3.17 0.017 0.041 12.68 5.3.16 0.015 0.043 12.67 5.3.15 0.017 0.040 12.67 5.3.14 0.015 0.040 12.67 5.3.13 0.011 0.046 12.66 5.3.12 0.013 0.042 12.66 5.3.11 0.015 0.054 12.66 5.3.10 0.018 0.049 12.14 5.3.9 0.010 0.043 12.13 5.3.8 0.019 0.058 12.11 5.3.7 0.014 0.043 12.11 5.3.6 0.014 0.042 12.10 5.3.5 0.014 0.040 12.04 5.3.4 0.014 0.050 12.04 5.3.3 0.013 0.039 12.01 5.3.2 0.016 0.043 11.79 5.3.1 0.011 0.042 11.75 5.3.0 0.016 0.047 11.74
preferences:dark mode live preview
142.2 ms | 1394 KiB | 7 Q