Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What about the garbled codes of thinkphp Chinese characters?

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces thinkphp Chinese character garbled how to do, the text is very detailed, has a certain reference value, interested friends must read!

Thinkphp Chinese character garbled solution: 1, find and open the thinkphp entry file;2, add "header ('Content-Type:text/html; charset= utf-8');" to the file.

Operating environment: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.

thinkphp database output Chinese utf-8 garbled code problem

Chinese garbled code appears when using thinkphp to connect mysql database is really a headache. No matter how to modify the field type of database, it is useless. I also checked everywhere and found that it is not a problem with mysql database. When we configure mysql database, we have configured the database to utf8 format, that is to say, the problem appears in thinkphp configuration itself. I checked it online and verified it. In fact, it is very simple. That is, add a sentence to the thinkphp entry file:

header('Content-Type:text/html; charset=utf-8');

In this way, we call the database verification again, and the garbled code becomes Chinese successfully.

Generally speaking, the reason for the appearance of Chinese garbled code is that the character coding is not unified, but what makes many people headache is that they do not know where to change the coding and how to unify it.

Where to agree to coding, and how to unify:

1. Code file (the easiest way to judge the file code is: open it with Notepad, and then click "Save as". There is the word "code" at the bottom of the window that appears. If it is not the code you want, change it to your code and save it to overwrite the original file);

2. html file header should be added, change utf-8 to the code you want to agree to;

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

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

The above is "thinkphp Chinese character garbled how to do" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report