From database creation to php reading json_encode Chinese is displayed correctly php json php json encode json encode Chinese

WBOY
Release: 2016-07-29 08:50:47
Original
1112 people have browsed it

Consensus: 1. First of all, it should be determined that Chinese should also be stored in varchar
2. Test using MySQL statement to view the character set
<br> show variables like "%char%"; <br> show variables like "collatio%"; <br>
If there are inconsistencies in encoding after checking (Chinese application gbk or utf8 support), you can specifically modify the value of a certain item, for example:

<code><span><span>SET</span> character_set_client=<span>'utf8'</span>;</span></code>
Copy after login

1. Create database

<code><span><span>CREATE</span><span>DATABASE</span> databasename
<span>CHARACTER</span><span>SET</span><span>'utf8'</span><span>COLLATE</span><span>'utf8_general_ci'</span>;</span></code>
Copy after login

2. Create table

<code>  CREATE TABLE industry_name (
                       <span>...</span>
                      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

</code>
Copy after login

Here is the same as ordinary The only difference in creating the table is the last sentence

Test to see if utf8 is unified

——————Now you can display Chinese when viewing mysql——————

json decode php,urlencode,eval,php json_encode,json encode中文,iconv,json_encode中文,urldecode,ch_json_encode,encode,arrayrecursive,json_unescaped_unicode,php json,php json encode,json encode中文

Then think Way to get Chinese in php
1. Write

<code><span>header("Content-Type</span>: <span>text/html;charset=utf8");</span></code>
Copy after login

in the front section of the code 2. Write

<code>mysqli_query(<span>$connection</span>, <span>"SET NAMES utf8"</span>);</code>
Copy after login

after the connection is established————Now you can display Chinese in the PHP page————-

Finally, if you need to use json_encode, Then you need to pay attention to the last point

<code><span>$json_string</span> = json_encode(<span>$result_row</span>, JSON_UNESCAPED_UNICODE);</code>
Copy after login

that is, add one more parameter to the ordinary json_encode, and now you are all done~

json decode php,urlencode,eval,php json_encode,json encode中文,iconv,json_encode中文,urldecode,ch_json_encode,encode,arrayrecursive,json_unescaped_unicode,php json,php json encode,json encode中文

Reference article:
(Transfer) The perfect solution to the Chinese garbled problem of Mysql (including database creation, data import, and web pages)
A complete solution to Chinese garbled characters in MySQL

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the correct display of json_encode Chinese from database creation to PHP reading, including the content of json_encode. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template