The rough solution is to ensure that characters are encoded in UTF8 when processing JSON. Specifically, we can change both the database encoding and page encoding to UTF8. Of course, if you like to use gbk encoding, you can convert the characters into UTF8 form before JSON processing
1. json_encode()
This is a commonly used function for JSON encoding of variables, but when the format of the text is not utf-8, there will be some problems with Chinese transcoding, such as when the text is gb2312
Example
The code is as follows | Copy code | ||||||||||||||||||||||||||||||||
'name' => 'Text 1' ),1 => array ( 'id' => '2',
It can be seen that even if UTF8-encoded characters are used, Chinese garbled characters appear when using json_encode. The solution is to process the characters with the function urlencode() before using json_encode, then json_encode, and use the function urldecode() to convert them back when outputting the result. The details are as follows:
http: //www.bkjia.com/PHPjc/632159.html TechArticle The rough solution is to ensure that characters are encoded in UTF8 when processing JSON. Specifically, we can change both the database encoding and page encoding to UTF8. Of course, if you like to use gbk encoding...
Related labels:
source:php.cn
Previous article:The time zone output time of the date function in php is incorrect_PHP tutorial
Next article:Solution to the invalid use of weight sorting in Dreamweaver CMS_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|