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

How to solve the problem of garbled information of php users

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

Share

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

This article mainly explains "how to solve the problem of garbled information of php users". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the problem of garbled php user information".

Php user information garbled solutions: 1, modify the database code; 2, modify the table code; 3, modify the field code; 4, modify the source file charset;5, modify the page charset;6, PHP page character set and so on.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

How to solve the problem of garbled information of php users?

The solution to the problem of Chinese garbled codes in utf-8 of php+mysql

It is recommended that the database be encoded with utf8

Summary of questions:

The default code for 1.MySQL database is utf8. If this code is inconsistent with your PHP page, it may cause mysql garbled.

When you create a table in 2.MYSQL, you will be asked to choose an encoding, which may cause MYSQL garbled if it is inconsistent with your web page encoding.

3.MYSQL can choose to add fields when creating a table. If this encoding is inconsistent with your web page coding, it may also cause MYSQL garbled.

4. The coding of the page submitted by the user is not consistent with the code of the page that displays the data, which will certainly lead to garbled php pages.

5. If the page entered by the user is big5 code, but the page entered by the user is gb2312, this 100% will cause PHP pages to garble.

The 6.PHP page character set is incorrect.

The encoding specified by the 7.PHP connection MYSQL database statement is incorrect.

The cause of garbled code generated by using mysql+php is well understood, so it is not difficult to solve it.

Solutions to different problems:

The default code for 1.mysql database is utf8. If this code is inconsistent with your PHP page, it may cause MYSQL garbled.

Modify the database encoding. If the database encoding is incorrect, you can execute the following command in phpmyadmin:

Alter DATABASE 'test' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin

The above command is to set the encoding of the test database to utf8.

When you create a table in 2.MYSQL, you will be asked to choose an encoding, which may cause MYSQL garbled if it is inconsistent with your web page encoding.

Modify the encoding of the table:

Alter TABLE 'category' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin

The above command is to change the encoding of a table category to utf8.

3.MYSQL can choose to add fields when creating a table. If this encoding is inconsistent with your web page coding, it may also cause MYSQL garbled.

Modify the encoding of the field:

Alter TABLE 'test' CHANGE' dd' 'dd' VARCHAR (45) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL

The above command is to change the field encoding of dd in the test table to utf8.

4. The coding of the page submitted by the user is not consistent with the code of the page that displays the data, which will certainly lead to garbled PHP pages.

If this situation is easy to solve, just check the page and modify the charset of the source file.

5. If the page entered by the user is big5 code, but the page entered by the user is gb2312, this 100% will cause PHP pages to garble.

This is also the case to modify the page charset.

The 6.PHP page character set is incorrect.

In order to avoid garbled code on the PHP page, the first sentence of the PHP page begins

Header ("content-type:text/html; charset=utf-8"); / / forcibly specify the encoding of the page to avoid garbled

The encoding specified by the 7.PHP connection MYSQL database statement is incorrect.

In the statement that connects to the database.

Mysql_connect ('localhost','user','password'); mysql_select_db (' my_db'); mysql_query ("set names' utf8'"); / / add more after the select database. I believe you have a deeper understanding of "how to solve the problem of garbled information of php users". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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