From database creation to PHP read json_encode Chinese correct display php json PHP JSON encode JSON encode Chinese

Source: Internet
Author: User
Tags php json
Consensus: 1. First of all, it should be determined that Chinese should also be stored with varchar.
2. Test using MySQL statement to view character set

show variables like "%char%";
show variables like "collatio%";

If you look at a place where the encoding is not uniform (Chinese app GBK or UTF8 support), you can modify the value of an item specifically, for example:

SET character_set_client='utf8';

1. Create a database

CREATEDATABASE databasenameCHARACTERSET'utf8'COLLATE'utf8_general_ci';

2. Create a table

  CREATE TABLE industry_name (                       ...                      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The only difference between this place and the normal table is the last word.

Test to see if UTF8 unified

—————— can now display Chinese in MySQL when viewed —————-

And try to get the Chinese in PHP.
1. Write in the previous section of the Code

header("Content-Typetext/html;charset=utf8");

2. After the establishment of connection, write

mysqli_query($connection"SET NAMES utf8");

———— can now display Chinese in the PHP page ————-

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

$json_string = json_encode($result_row, JSON_UNESCAPED_UNICODE);

That is, in the ordinary json_encode to add a parameter, so it is all done ~

Reference article:
Go MySQL Chinese garbled problem perfect solution (including build library, import data, Web page)
Completely solve the MySQL Chinese garbled method

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the creation from the database to PHP read Json_encode Chinese correct display, including the json_encode aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.