Solution to the problem of UTF-8 garbled by ASP _ Application Tips

Source: Internet
Author: User
This is the problem of page coding. Commonly used in Chinese is gb2312 such words show Chinese basically will not appear garbled. But sometimes we use a utf-8 format that is commonly used internationally. If the Utf-8 format people are not very familiar with the words is easy to appear garbled.

A lot of friends asked me why in the ASP specified codepage 65001 also often display garbled. Wit here will explain this problem in detail, lest many friends again detours, even repel UTF-8.
ASP Web page UTF8 garbled if you do not know what UTF-8 is, the wit suggested that you first to search for UTF-8 related information.
UTF-8 coding is more and more people accept even like, certainly is reasonable, in the WEB2.0 prevalent today, in large talk about the compatibility of multiple browsers at the same time, have to think of different character encoding caused by the garbled phenomenon also need to be very good treatment ...
N years ago, IE6 all the following versions, as long as the corresponding font is not installed, access to related pages are garbled, for example, I am IE5 (Windows2000 default) version, in the absence of the installation of IE Traditional Chinese library, access to any traditional Web site will be garbled, Of course, the premise is that the page uses the BIG5 charset, and UTF-8 as an international code can be very good to deal with the problem, as long as the page is stored as a UTF-8 encoding format, Then on the page on the codepage and charset all defined as Utf-8 can be in any client browser to display exactly the right content, completely not garbled ...

All right, wit. Here take the ASP page as an example, with an example to see the specific operation bar:

In this talent recommended to write code with EditPlus, wit also wrote a special editplus of the use of the tutorial, interested friends can click here to see.

Open a new ASP page, I believe that playing ASP's friends will notice that many downloads of the source code, the top of the page generally have a sentence:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
The front of the language should not say more, VBScript is the ASP default scripting language, in fact, can not write, write as if it will affect the efficiency of the page execution, here we do not discuss this issue. The codepage is the key, the purpose is to tell the browser, this page is what the code, 936 of the representative is simplified Chinese, and 950 for Traditional Chinese, 65001 is what we say today UTF-8 code. We'll change 936 to 65001, the whole sentence as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
Plus the output of several Chinese text to see if you can correctly display it.
<%
Response.Write "First Test UTF-8 page"
%>
OK, directly click "Save", the implementation of this page to see if there is no accident, we may see the display is "a UTF-8 page" of these words, Chinese have garbled phenomenon, what reason?
OK, please click on the top of the "File" menu, select "Save As", the bottom line has a code, the default should be ANSI, please point down the box, select UTF-8, and then save, then try to do, if not an accident, chaos more powerful, oh, dizzy it. Don't worry, think about why, Because we do the page is returned by HTML, before we write HTML, see the body front, that is, head has a meta, should be this:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
That is, specify the page to return the result in gb2312 encoding, be sure to write in the back of the output of the return results. We all know gb2312 is Simplified Chinese, we say today is UTF-8 code, we will gb2312 to UTF-8 it, 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"
%>
Take a look at it again, well, this time the normal show ....

ASP Web page UTF8 garbled conclusion: using UTF-8 encoding, in addition to save the file as a UTF-8 format, we also need to specify both codepage and CharSet.

To ensure that the ASP leaf will not appear garbled code should be such:
(assumed to be UTF-8 leaves)
<%@ codepage=65001%>
<% response.codepage=65001%>
<% response.charset= "UTF-8"%>
Public file code.asp can be established, and all pages contain this encoding designation.
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.