HTML garbled reason and Web page garbled solution method

Source: Internet
Author: User

The reason why HTML Web page garbled is mainly the HTML source code text content and HTML coding is caused by different. However, either way, garbled characters are required to set the page encoding at the beginning of the page.


CharSet Encoding settings


HTML page garbled effect

First, garbled causes-TOP

1, such as the Web page source code is GBK encoding, and the content of the text is UTF-8 encoded, so that the browser will appear garbled HTML. Conversely, the page is encoded UTF-8, the content is GBK will also appear garbled.

2, HTML page encoding is GBK, and the program from the database to bring up the rendering is UTF-8 encoded content will also cause coding garbled.

3, the browser can not automatically detect the page encoding, resulting in garbled pages.

Second, to solve the garbled method-TOP

First, the HTML page source code is different from the Chinese text input encoding.

Workaround:

Using software to edit HTML page content, we recommend using DW Software for HTML code editing and development.

Try not to edit the HTML code directly using Notepad.

Second, if the page set encoding is GBK, and the database storage data encoding format is UTF-8, this time the program query database data display data Qianjin Township program transcoding can be.

For example PHP program +mysql query display data transcoding:
1, mysql_query ("SET NAMES ' UTF8 '"); Transcode query data to UTF8, which translates to Utf-8
2, mysql_query ("SET NAMES ' GBK '");//transcode query data to GBK, such as gbk2312

When writing a database connection file, write:

    1. $conn = mysql_connect ("$host", "$user", "$password");
    2. mysql_query ("SET NAMES ' UTF8 '");
    3. mysql_select_db ("$database", $conn);

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

    1. <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />

This way, regardless of the input database of the Chinese, or the page display, it is normal.
In DW version CS4, the UTF8 page is generated by default.

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

    1. mysql_query ("SET NAMES ' GBK '");

The page should also be changed accordingly:

    1. <Meta http-equiv= "content-type" content= "text/html; charset=gb2312 " />

Other ASP program or other program language website according to the actual situation to Baidu query conversion encoding method.

Third, the browser causes garbled characters.
This may be caused by your webpage not setting Meta charset encoding. Causes the browser to not recognize your page's default encoding type. Workaround:

1, if the browser appears garbled page, in the browser to find the conversion code menu.

In the IE9 browser, you need to transcode the page blank out of the right mouse button, you can select "Encoding."
When browsing a webpage that requires transcoding in the browser, the menu "view" and "encode" to select the conversion encoding
Google browser to browse the need to transcode the page, click on the top right corner of the "three horizontal" icon select "Tools"--"encoding" can choose to switch the page encoding to allow the browser to browse this page is not garbled.


Visit the browser to switch the current page encoding

2. If you develop a webpage, you must add the Meta CharSet encoding tag to the webpage.

    1. <Meta http-equiv= "content-type" content= "text/html; charset=gb2312 " />

Or

    1. <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />

If the conversion time, not the Notepad editor to add Meta CharSet encoding tag is completed, this will also cause garbled, that is, because the direct Notepad to add or modify the encoding format, and the corresponding HTML hypertext document content does not change with the addition or modification of the encoding format, this time requires the real meaning of transcoding , so it is best to use development software to add and modify the code.

Recommended to modify the code in the DW software. Encode, modify, or add in the DW software and reload the encoded Web page.

HTML garbled reason and Web page garbled solution method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.