Home > Article > Backend Development > Solve the garbled problem of PHP beginners_PHP tutorial
Garbled characters have always been a very big problem that troubles PHP beginners. Now we will summarize the causes and solutions of garbled characters:
1. HTML page encoding: meta http-equiv=content-type content=text/html ; charset=utf-8 The encoding here must be consistent with the database encoding and the connection database encoding;
2. The storage encoding of the file: For example, the file inde.php, change its storage encoding to the required encoding. Just use text editing software such as EditPlus to save the file as, and select the correct encoding in the encoding (many people will ignore this);
3. Database encoding: For example, if you use phpmyadmin, select the database and select the operation option. There is an arrangement below, which should also be set to a unified encoding;
4. Table encoding: The operation is similar to the third point. I won’t repeat it here;
5. Field encoding: When creating fields in a table, there is an arrangement. If the content contains Chinese characters, it must be changed to a unified encoding;
6. When connecting to the database, add the sentence mysql_query (set names utf8) after mysql_select_db();
7. Local test (just encountered) After the successful website is uploaded to the Internet, there will be garbled characters. It may be that the correct encoding was not selected when exporting data locally, so there will be garbled characters after importing to the web.
In fact, as long as you are careful, you can completely solve the php garbled problem. The difficulty is not technology, but carefulness. (www.bkjia.com)