Summary of Solutions to asp UTF-8 garbled Problem

Source: Internet
Author: User

This is a Web page encoding problem. Generally, the Chinese version uses gb2312 to display Chinese characters without garbled characters. However, sometimes we use an international common UTF-8 format. If the UTF-8 format is not well understood, garbled characters may occur.

Many friends have asked me why codepage 65001 is specified in ASP and garbled characters are often displayed. here I will explain this problem in detail, so as to avoid many friends detour, even exclusion of UTF-8.
Asp Web page utf8 garbled if you do not know what UTF-8 is Dongdong, then I suggest you first to search for UTF-8 related information.
UTF-8 encoding is accepted by more and more people or even like, it must be reasonable, in the popular web today, while talking about multi-browser compatibility, I have to think of the garbled characters caused by different character encoding. It also needs to be well handled .....
If no font library is installed for all IE6 versions earlier than N years ago, access to related pages will be garbled. For example, I am IE5 (default Windows version, without installing the IE traditional Chinese font, the website accessing any traditional Chinese page will be garbled. Of course, the premise is that the page uses BIG5 Charset, UTF-8 as an international code can be very good to deal with this problem, as long as the page is stored as a UTF-8 encoding format, on the page, define codepage and charset as UTF-8 to display the correct content in any client browser without any garbled characters ......

Let's take the ASP page as an example. Let's look at the specific operations for an instance:

In this case, we recommend that you use Editplus to write code, and then write an Editplus tutorial. If you are interested, click here.

Open and create an ASP page. I believe all the users playing ASP will notice that many of the downloaded source code usually have one sentence at the top of the page:
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
The preceding language should be needless to say. vbscript is the default scripting language of ASP. In fact, you do not need to write it. Writing It seems to affect the page execution efficiency. We will not discuss this issue here. the following codepage is the key, the purpose is to tell the browser, the page is what encoding, 936 represents Simplified Chinese, and 950 represents traditional Chinese, 65001 is what we said today UTF-8 encoding. change 936 to 65001. The entire sentence is as follows:
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %>
Add a few texts to check whether the text is correctly displayed.
<%
Response. Write "first test UTF-8 page"
%>
OK, click "save" directly, execute this page to see if there is no accident, you may see that the display is "A UTF-8 page" the words, Chinese garbled phenomenon, why?
OK, please click the top "file" menu, select "Save as", the bottom line has a encoding, the default should be ANSI, please click the drop-down box, select UTF-8, click Save and try again. If there is no accident, the mess will be worse. don't worry, think about the reason, because the page we made is returned by HTML. When we wrote HTML, we saw a meta in front of the body, that is, in the head, which should be like this:
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
That is, to specify that the page returns results in gb2312 encoding, it must be written before the returned result output. we all know that gb2312 is simplified Chinese, we are talking about UTF-8 code today, we will change gb2312 to UTF-8, all the code is as follows:
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<%
Response. Write "first test UTF-8 page"
%>
Run the command again. Well, this time it is normal .......

Asp Web page utf8 garbled conclusion: Using UTF-8 encoding, in addition to the file to save as UTF-8 format, also need to specify codepage and charset.

The code to ensure that no garbled characters are displayed on asp should be as follows:
(Assuming it is the leaves of the UTF-8)
<% @ CODEPAGE = 65001%>
<% Response. CodePage = 65001%>
<% Response. Charset = "UTF-8" %>
You can create a public file code. asp. All pages contain this encoding.

Related Article

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.