Home Web Front-end HTML Tutorial Why HTML web pages are garbled and how to solve them

Why HTML web pages are garbled and how to solve them

Nov 21, 2017 am 11:58 AM
html Why solve

Sometimes the web page we created is garbled when opened, so how do we solve this situation? The following will bring you the causes of garbled codes and methods to solve them.

1. Reasons for 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 way, 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.

2. 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, then the program queries the database data and displays the data before entering the native program for transcoding.

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

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

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

When writing the database connection file, write:

1

2

3

$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" />

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 as:

1

mysql_query(&quot;SET NAMES &#39;GBK&#39;&quot;);

Copy after login

, then the page should also become:

1

&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;

Copy after login
Copy after login

Other asp programs or other programming language websites are based on For the actual situation, go to Baidu to check the conversion encoding method.

The third type is that the browser causes garbled characters.

This may be caused by your web page 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.


#2. If you develop your own web page, you must add meta charset encoding tags to the web page.

1

&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;

Copy after login
Copy after login


or

1

&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;

Copy after login

If the conversion is not completed by adding the meta charset encoding tag in Notepad, this will also cause garbled characters. That is because the direct After Notepad adds or modifies the encoding format, the content of the corresponding Html hypertext document does not change with the addition or modification of the encoding format. At this time, true transcoding is required, so it is best to use development software to add and modify encoding.

It is recommended to modify the encoding in DW software. Modify or add the encoding in the DW software and reload the encoded web page.

Friends who need the solution to garbled web pages can save it, and please continue to pay attention to other updates on this site.

Related reading:

How to use checkbo in HTML


Naming rules in HTML


How to modify the font color in html

The above is the detailed content of Why HTML web pages are garbled and how to solve them. 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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

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)

How to fine-tune deepseek locally How to fine-tune deepseek locally Feb 19, 2025 pm 05:21 PM

How to fine-tune deepseek locally

deepseek why can't you log in deepseek login portal deepseek why can't you log in deepseek login portal Feb 19, 2025 pm 05:00 PM

deepseek why can't you log in deepseek login portal

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

How do you parse and process HTML/XML in PHP?

Why can't the Bybit exchange link be directly downloaded and installed? Why can't the Bybit exchange link be directly downloaded and installed? Feb 21, 2025 pm 10:57 PM

Why can't the Bybit exchange link be directly downloaded and installed?

Free market software app website Free market software app website Mar 05, 2025 pm 09:03 PM

Free market software app website

Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Mar 04, 2025 pm 04:06 PM

Why is Bittensor said to be the 'bitcoin' in the AI ​​track?

gateio exchange app old version gateio exchange app old version download channel gateio exchange app old version gateio exchange app old version download channel Mar 04, 2025 pm 11:36 PM

gateio exchange app old version gateio exchange app old version download channel

Bitcoin: The 'barometer' of global liquidity? Bitcoin: The 'barometer' of global liquidity? Mar 04, 2025 pm 06:39 PM

Bitcoin: The 'barometer' of global liquidity?

See all articles