Today, we will store json_encode format information in php in MySQL. there is no problem in English, but when it comes to Chinese, it will become a bunch of information similar to uxxxx. 1. cause analysis:
Today, we will store json_encode format information in php in MySQL. there is no problem in English, but when it comes to Chinese, it will become a bunch of information similar to uxxxx.
1. cause analysis:MySQL does not store unicode characters when it is stored in the database. MySQL only supports basic multilingual flat characters (0x0000-0 xFFFF). please try to store the opposite synonym :).
Update: MySQL 5.5.3 (not yet GA). supplementary characters are supported. if you use UTF8MB4 encoding and json_encode Chinese, each Chinese character is encoded as "uxxxx ", when the database is saved, "" is blocked and directly changed to "uxxxx ".
2. solve the problem:If you know the reason, you can solve the problem. you can choose another storage method, or escape "\" to keep "".
Our solution:
1. to prevent json_encode from converting Chinese to unicode encoding. PHP5.4, you have added an option for Json: JSON_UNESCAPED_UNICODE. After this option is added, Chinese characters are not automatically encoded.
$ Test = json_encode ("Shenzhen", JSON_UNESCAPED_UNICODE );
2. urlencode, json_encode, and urldecode are used to ensure that Chinese characters are not converted to unicode.
- $ Test = urldecode (json_encode (array ('brief '=> urlencode ('Introduction'), 'title' => urlencode (title )));
-
3. escape "" as "\" to avoid removing the unicode Chinese prefix ''from mysql as a special character