Home PHP Framework ThinkPHP What to do if Chinese garbled characters appear in thinkphp5

What to do if Chinese garbled characters appear in thinkphp5

Dec 06, 2022 am 10:14 AM
thinkphp5

thinkphp5 Chinese garbled solution: 1. Add "character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci" to mysqld in my.ini; 2. Indicate the characters in the background program php code Encoding "header('Content-Type: text/html; charset=utf-8');".

What to do if Chinese garbled characters appear in thinkphp5

The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.

thinkphp5 What should I do if the Chinese characters are garbled?

thinkphp5 reports a utf-8 encoding error even when accessing the database

thinkphp5 reports a utf-8 encoding error even when accessing the database. The reason for Chinese garbled characters is The character encoding is not uniform. If Chinese garbled characters appear, you need to add the following code.

Add the following statement under mysqld in my.ini under D:\phpStudy\PHPTutorial\MySQL:

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Copy after login

The sample code is as follows:

What to do if Chinese garbled characters appear in thinkphp5

Extended information:

thinkphp5 reports a utf-8 encoding error even when accessing the database. Possible errors:

1. Code file (the simplest way to determine the encoding of the file is : Open with Notepad, and then click "Save As". There will be the word "Encoding" at the bottom of the window that appears. If it is not the encoding you want, change it to your encoding and save it to overwrite the original file).

2. The header of the html file should be added with and change utf-8 to Just the encoding you want to agree with.

3. The database connection code should select the corresponding character encoding. The code for selecting the character encoding for mySql is: mysql_query("SET NAMES 'utf-8';"); Please query the codes of other databases by yourself.

4. The background program code php needs to indicate the character encoding, header('Content-Type: text/html; charset=utf-8');.

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of What to do if Chinese garbled characters appear in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I get an error when deploying thinkphp5 in Pagoda? What should I do if I get an error when deploying thinkphp5 in Pagoda? Dec 19, 2022 am 11:04 AM

What should I do if I get an error when deploying thinkphp5 in Pagoda?

What should I do if thinkphp5 post cannot get the value? What should I do if thinkphp5 post cannot get the value? Dec 06, 2022 am 09:29 AM

What should I do if thinkphp5 post cannot get the value?

How to get the requested URL in thinkphp5 How to get the requested URL in thinkphp5 Dec 20, 2022 am 09:48 AM

How to get the requested URL in thinkphp5

What should I do if thinkphp5 url rewriting fails? What should I do if thinkphp5 url rewriting fails? Dec 12, 2022 am 09:31 AM

What should I do if thinkphp5 url rewriting fails?

How to remove thinkphp5 title bar icon How to remove thinkphp5 title bar icon Dec 20, 2022 am 09:24 AM

How to remove thinkphp5 title bar icon

What should I do if thinkphp5 prompts that the controller does not exist? What should I do if thinkphp5 prompts that the controller does not exist? Dec 06, 2022 am 10:43 AM

What should I do if thinkphp5 prompts that the controller does not exist?

How to query yesterday's data in ThinkPHP5 How to query yesterday's data in ThinkPHP5 Dec 05, 2022 am 09:20 AM

How to query yesterday's data in ThinkPHP5

How to set error prompts in thinkphp5 How to set error prompts in thinkphp5 Dec 07, 2022 am 10:31 AM

How to set error prompts in thinkphp5

See all articles