Unicode vs utf 8
unicode is utf-16, which uses two bytes(8bits per byte to represnet 1 char like chinese char), utf-8 uses 1 byte to represent 1 char
https://stackoverflow.com/questions/643694/what-is-the-difference-between-utf-8-and-unicode
unicode has optimized performances
Windows handles so-called "Unicode" strings as UTF-16 strings, while most UNIXes default to UTF-8 these days. Communications protocols such as HTTP tend to work best with UTF-8, as the unit size in UTF-8 is the same as in ASCII, and most such protocols were designed in the ASCII era. On the other hand, UTF-16 gives the best average space/processing performance when representing all living languages.
PHP json_decode debug
$data = file_get_contents('http://www.mywebservice');
if(!empty($data))
{
$obj = json_decode($data);
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - JSON_ERROR_NONE';
break;
case JSON_ERROR_DEPTH:
echo ' - JSON_ERROR_DEPTH';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - JSON_ERROR_STATE_MISMATCH';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - JSON_ERROR_CTRL_CHAR';
break;
case JSON_ERROR_SYNTAX:
echo "\r\n\r\n - SYNTAX ERROR \r\n\r\n";
break;
case JSON_ERROR_UTF8:
echo ' - JSON_ERROR_UTF8';
break;
default:
echo ' - Unknown erro';
break;
}
https://stackoverflow.com/questions/17219916/json-decode-returns-json-error-syntax-but-online-formatter-says-the-json-is-ok
PHP do not use stripslashes for unicode :
https://stackoverflow.com/questions/50423405/php-replace-json-with-the-correct-unicode-symbol
No comments:
Post a Comment