of the web page; 2. Modify the encoding of the file itself to utf8; 3. Set the character set and sorting rules to utf8 when creating the database in MySQL. Can."/> of the web page; 2. Modify the encoding of the file itself to utf8; 3. Set the character set and sorting rules to utf8 when creating the database in MySQL. Can.">
search
HomeBackend DevelopmentPHP ProblemHow to solve php html garbled code

How to solve php html garbled code

Dec 02, 2020 am 09:16 AM
htmlphpGarbled characters

php html garbled solution: 1. Add "charset=utf8" to the web page; 2. Modify the encoding of the file itself to utf8; 3. Set the character set and sorting rules when creating the database in MySQL It can be utf8.

How to solve php html garbled code

Recommended: "PHP Video Tutorial"

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, Dell G3 computer, this method is suitable for all brands of computers.

Solution to php html garbled code

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

In fact, there are several main reasons that lead to garbled web pages. The solutions are given below.

1. HTML character encoding problem

This problem is more common, and it is also the most obvious and easiest to solve.

Add in the page

:

is enough.

2. PHP character encoding problem

This is similar to the above.

Add:

header("Content-type:text/html;charset=utf8"); above the file.

3. The encoding problem of the file itself

Not only our content is encoded, but the file itself is also encoded.

Use Notepad to open a file and you can see the content displayed in the lower right corner.

is the encoding of the file itself.

You can use "Format" on the Notepad toolbar to convert the encoding for our files.

4. Database encoding problem

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%'

You can see the 7 values ​​

character_set_client 

character_set_connection
character_set_database
character_set_filesystem
character_set_results
character_set_server

character_set_system

.

The set names ut8 command can set the three

character_set_client 
character_set_connection
character_set_results

to utf8.

So when creating a database in MySQL, pay attention to setting the character set and collation rule to utf8,.

In the file connecting to the database, perform mysql_query("SET NAMES UTF8") on the database.

can basically guarantee that the web page will not have garbled code problems.

The above is the detailed content of How to solve php html garbled code. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools