There are three reasons why HTML pages are garbled. So today we're going to take a look at three different causes and solutions for three problems.
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.
Garbled cause
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.
Solving garbled methods
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:
$conn = mysql_connect ("$host", "$user", "$password"); mysql_query ("SET NAMES ' UTF8 '"); mysql_select_db ("$database", $conn);
Then, when making the page, pay attention to this sentence:
<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:
mysql_query ("SET NAMES ' GBK '");
The page should also be changed accordingly:
<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.
Cause the HTML page garbled reason and the solution is so much, the need for friends can save, but also please keep your attention to other updates on this site.
Related reading:
How to use label labels in HTML
How to modify HTML caption tag elements
using CSS to manipulate border's tips