Home Web Front-end CSS Tutorial Why is html garbled and how to solve it

Why is html garbled and how to solve it

Nov 21, 2017 pm 05:03 PM
html Why solve

There are three reasons that cause html web pages to be garbled. So today we will talk about three different causes and solutions to the three problems.

The cause of garbled HTML web pages is mainly caused by the difference between the Chinese text content in the HTML source code and the HTML encoding. But no matter which situation causes garbled code, the web page encoding needs to be set at the beginning of the web page.

Causes of garbled codes

1. For example, the source code of the web page is encoded by gbk, and the Chinese characters in the content are encoded by utf-8. In this case, html garbled codes will appear when the browser is opened. On the contrary, if the web page is encoded in utf-8 and the content is gbk, garbled characters will appear.

2. The encoding of the html web page is gbk, and the program calls out the content encoded in utf-8 from the database, which will also cause encoding garbled characters.

3. The browser cannot automatically detect the encoding of the web page, causing the web page to be garbled.


Methods to solve garbled characters

The first one is that the source code encoding of the html web page is different from the Chinese character input encoding.

Solution:

Use software to edit HTML web page content. It is recommended to use DW software for HTML code editing and development.

Try not to use Notepad directly to edit HTML code.


Second, if the web page setting encoding is gbk, and the database storage data encoding format is UTF-8, at this time the program queriesthe database The data display data can be transcoded before entering the local program.

For example, PHP program + mysql query display data transcoding:

1, mysql_query("SET NAMES 'UTF8'"); //Transcode the query data to utf8, that is, converted to utf-8

2, mysql_query("SET NAMES 'GBK'");//Transcode the query data to GBK, such as gbk2312

when writing the database connection When writing the file, write:

$conn = mysql_connect("$host","$user","$password"); 
mysql_query("SET NAMES 'UTF8'"); 
mysql_select_db("$database",$conn);
Copy after login

Then when making the page, pay attention to this sentence:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Copy after login

In this way, regardless of the Chinese input into the database or the page display, everything will be normal.

In the DW CS4 version, the utf8 page is also generated by default.

Similarly, if you write the database connection file at the beginning:

mysql_query("SET NAMES 'GBK'");

Then the page should also become:

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
Copy after login

OthersASP programs or other programming language websites can check the conversion encoding method on Baidu according to the actual situation.


The third type is that the browser causes garbled characters.

This may be caused by your webpage not setting meta charset encoding. As a result, the browser cannot recognize the default encoding type of your web page. Solution:

1. If the web page is garbled when browsing in the browser, find the menu to convert the encoding in the browser.

In IE9 browser, right-click the blank page of the webpage that needs to be transcoded and select "Encoding".

When browsing web pages that need to be transcoded in Maxthon Browser, menu "View"-->"Encoding" to select the conversion encoding

When browsing web pages that need to be transcoded in Google Chrome , click the "three horizontal" icon in the upper right corner and select "Tools" --> "Encoding" to choose to switch the web page encoding so that the browser will not browse this web page with garbled characters.

There are so many reasons and solutions for garbled HTML web pages. Friends who need it can save it. Please also continue to pay attention to other updates of this site.

Related reading:

How to use label tags in html


HTML title tag element How to modify


Tips for using CSS to manipulate borders

The above is the detailed content of Why is html garbled and how to solve it. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1668
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to display child categories on archive page of parent categories How to display child categories on archive page of parent categories Apr 19, 2025 pm 11:54 PM

Do you want to know how to display child categories on the parent category archive page? When you customize a classification archive page, you may need to do this to make it more useful to your visitors. In this article, we will show you how to easily display child categories on the parent category archive page. Why do subcategories appear on parent category archive page? By displaying all child categories on the parent category archive page, you can make them less generic and more useful to visitors. For example, if you run a WordPress blog about books and have a taxonomy called "Theme", you can add sub-taxonomy such as "novel", "non-fiction" so that your readers can

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Apr 21, 2025 am 08:57 AM

Factors of rising virtual currency prices include: 1. Increased market demand, 2. Decreased supply, 3. Stimulated positive news, 4. Optimistic market sentiment, 5. Macroeconomic environment; Decline factors include: 1. Decreased market demand, 2. Increased supply, 3. Strike of negative news, 4. Pessimistic market sentiment, 5. Macroeconomic environment.

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

HTML as a Markup Language: Its Function and Purpose HTML as a Markup Language: Its Function and Purpose Apr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

What is the difference between php framework laravel and yii What is the difference between php framework laravel and yii Apr 30, 2025 pm 02:24 PM

The main differences between Laravel and Yii are design concepts, functional characteristics and usage scenarios. 1.Laravel focuses on the simplicity and pleasure of development, and provides rich functions such as EloquentORM and Artisan tools, suitable for rapid development and beginners. 2.Yii emphasizes performance and efficiency, is suitable for high-load applications, and provides efficient ActiveRecord and cache systems, but has a steep learning curve.

Why should you listen Why should you listen Apr 21, 2025 pm 09:00 PM

Concordium: A public first-level blockchain platform that takes into account privacy and compliance is a public first-level blockchain platform. Its core lies in the clever integration of identity verification with privacy and regulatory compliance. Founded in 2018 by Lars Seier Christensen, the platform’s core technology embeds cryptographic identities at the protocol level of each transaction. This unique design ensures responsibility traceability while protecting user privacy, effectively solving the problem of conflicts between anonymity and regulatory requirements in the blockchain field. To alleviate this problem, Concordium utilizes Zero Knowledge Proof (ZKP) technology, allowing users to verify specific identity attributes without the need to disclose unnecessary personal information. This means that, despite every

How to process sensor data in C? How to process sensor data in C? Apr 28, 2025 pm 10:00 PM

C is suitable for processing sensor data due to its high performance and low-level control capabilities. Specific steps include: 1. Data collection: Obtain data through the hardware interface. 2. Data analysis: convert the original data into available information. 3. Data processing: filtering and smoothing processing. 4. Data storage: Save data to a file or database. 5. Real-time processing: Ensure the efficient and low latency of the code.

See all articles