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

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

Recovering deleted rows directly from the database is usually impossible unless there is a backup or transaction rollback mechanism. Key point: Transaction rollback: Execute ROLLBACK before the transaction is committed to recover data. Backup: Regular backup of the database can be used to quickly restore data. Database snapshot: You can create a read-only copy of the database and restore the data after the data is deleted accidentally. Use DELETE statement with caution: Check the conditions carefully to avoid accidentally deleting data. Use the WHERE clause: explicitly specify the data to be deleted. Use the test environment: Test before performing a DELETE operation.

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting
