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 Chinese garbled code in php file display

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to solve the problem of Chinese garbled code in php document display". In daily operation, I believe that many people have doubts about how to solve the problem of Chinese garbled code in php document display. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the problem of "how to solve the problem of Chinese garbled code in php document display". Next, please follow the editor to study!

Php file display Chinese garbled solutions: 1, add header statement on the top of the PHP document; 2, add utf-8 coding at the beginning of the page; 3, execute "mysql_query ('SET NAMES UTF8');"

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

One: a hybrid page solution of HTML and PHP

How to mix HTML and PHP, in addition to following the action described in the first method, you need to add this code to the top of the PHP file:

Second: the problem of Chinese garbled code in pure PHP pages (the data is static)

If your PHP page is garbled, just add the following code at the beginning of the page.

Third: the problem of Chinese garbled code in PHP+Mysql

In addition to following the third method, add database coding before your data is queried / modified / added. Also, it is worth noting that the UTF8 here is different from the previous one, and there is no horizontal line in the middle.

How you use MySQL version 4.1 or later, you can set a character encoding after linking to the database, like the following

UTF-8 coding is only one kind of coding, if you do not want to use utf-8 coding, you can also use other codes, just change the UTF-8 to the code you want to use. At present, GB2312 and UTF-8 are mainly used in the development of Chinese websites.

One thing to pay attention to: the mysql_query ("set names' code'") added before the php program that needs to do database operations; the encoding must be consistent with the php code. If the php code is gb2312, then the mysql code is gb2312, if it is utf-8, then the mysql code is utf8, so that there will be no garbled code when inserting or retrieving data.

At this point, the study on "how to solve the problem of displaying Chinese garbled codes in php documents" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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