Home >Backend Development >PHP Tutorial >[PHP] Solve the problem of garbled html web pages, phphtml web pages are garbled_PHP tutorial

[PHP] Solve the problem of garbled html web pages, phphtml web pages are garbled_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:53:51841browse

[PHP] Solve the problem of garbled html web pages, phphtml web pages are garbled

When making a web page by yourself, you often encounter the problem of garbled web pages.

In fact, there are several main reasons for garbled web pages, and the solutions are given below. 1. HTML character encoding problem This problem is the most common, the most obvious, and the easiest to solve. In the of the page, add: That’s it. 2. PHP character encoding problem This is similar to above. Above the file add: header("Content-type:text/html;charset=utf8"); that's it. 3. Encoding problem of the file itself Not only is our content encoded, but so is the file itself. Use Notepad++ to open a file and you can see the content displayed in the lower right corner. It's the encoding of the file itself. You can use "Format" on the Notepad++ toolbar to convert the encoding for our files. 4. Database encoding issue MySQL data is latin1 encoded when installed by default, so it is likely to cause garbled web pages without paying attention. Use root to enter the database, Enter show variables like 'character%' can be seen character_set_client character_set_connection
character_set_database
character_set_filesystem
character_set_results
character_set_server character_set_system these 7 values. ​ Among them, the set names ut8 command can set character_set_client character_set_connection character_set_results These 3 are set to utf8. ​ So when creating a database in MySQL, pay attention to setting the character set and collation to utf8,. Then in the file connecting to the database, perform mysql_query("SET NAMES UTF8") on the database. It can basically guarantee that the web page will not have garbled code problems.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1052443.htmlTechArticle[PHP] Solve the problem of garbled html web pages. phphtml web pages are garbled. When making a web page by yourself, you will often encounter web pages. Garbled code problem. In fact, there are several main reasons for garbled web pages, including...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn