Why HTML web pages are garbled and how to solve them
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:
$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" />
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:
mysql_query("SET NAMES 'GBK'");
, then the page should also become:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
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.
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
or
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
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:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

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

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

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.

In IntelliJ...

React operates in HTML via virtual DOM. 1) React uses JSX syntax to write HTML-like structures. 2) Virtual DOM management UI update, efficient rendering through Diffing algorithm. 3) Use ReactDOM.render() to render the component to the real DOM. 4) Optimization and best practices include using React.memo and component splitting to improve performance and maintainability.
