Garbled characters in php web pages are generally caused by the difference between the encoding used when creating the database and the encoding of the php web page.
If you do not specify the encoding for the database created with phpmyadmin, the default encoding is latin1_swedish_ci, which means Swedish is not size-sensitive. Write, and the web pages we make in China are either GBK or GB2312 encoded, so it would be strange if there are no garbled characters.
1. Specify the encoding when creating the database.
Here again Let me talk about the commonly used encodings to avoid confusion for novices:
If you are making a simplified Chinese web page, then you use GB2312 encoding, gb2312_chinese_ci when building the database.
If you are doing It is a traditional Chinese web page, so when you create the database, you must use gib5 encoding, big5_chinese_ci
If the web page you make has both simplified and traditional Chinese, it is recommended that you use GBK encoding, gbk_chinese_ci. GBK contains more character codes than GB2312 Many, of course Traditional Chinese is also included.
If you are making a multi-language web page, it is recommended that you use UTF-8 encoding. There are two utf8 encoding options in mysql: utf8_unicode_ci and utf8_general_ci. The author generally uses utf8_general_ci , Regarding the difference between these two encodings, please refer to another article on this site: The difference between the proofreading set utf8_unicode_ci and utf8_general_ci in Mysql
We use UTF-8 encoding as an example to create a database as shown in the figure:
2. Use mysq_query to set the encoding when connecting to the database with php
The new web page created by IDE is gb2312, but I changed the built web page to big5. How can there be no garbled characters? The solution is very simple. Save it as again and specify Just encode it and it’s OK.
www.bkjia.com