UTF-8 Chinese garbled how to solve

Source: Internet
Author: User

Why in the ASP specified the codepage for 65001 also often appear in Chinese display garbled. Wit here will explain this problem in detail, lest many friends again detours, even exclude UTF-8.

If you do not know what UTF-8 is, then the wit suggested that you go to search the relevant information UTF-8.

UTF-8 coding is more and more people accept and even like, there must be a reason. In WEB2.0 popular 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 Chinese 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 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 this problem, as long as the page is stored as UTF-8 encoding format, and then on the page will be codepage and charset all defined as UTF-8, you can in any client browser to display exactly the right content, completely not garbled.

OK, here take the ASP page for example, take an example to see the specific operation bar:

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 in the back is the key, the purpose is to tell the browser, this page is what kind of code, 936 representative is Simplified Chinese, and 950 for Traditional Chinese, 65001 is what we say today UTF-8 code. We'll change the 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", and then perform a try, if not an accident, chaos more powerful, oh, dizzy it. Don't worry, think about the reason, because we do the page is HTML back, 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, the specified page returns the result in gb2312 encoding, and must be written in front of the returned results output. We all know gb2312 is Simplified Chinese, we say today is UTF-8 code, we will gb2312 to UTF-8 it, all the code as follows:
<% @Language = "VBScript" codepage= "65001"%>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<%response.write "First Test UTF-8 page"%>

Last: When saving the file, please select the encoding for UTF-8

The easiest way to do this is to use Notepad to open and save UFT-8 ...

Take a look at it again, well, this time the normal show ...

Conclusion: In addition to saving the file as UTF-8 format, it is necessary to specify codepage and charset at the same time using UTF-8 coding.
Some people say do not use FSO to read and write files, replace ADODB.stream, use. Charset = "Utf-8", there will be no garbled. But I still appear garbled, it seems that this is not the best way.

My solution is to add this sentence: session.codepage= "65001" (use once on the OK, and later (restart it again) did not appear garbled, how. )

Summarize:

1, all documents using utf-8 preservation;

2, ASP file plus the following three lines of code:

①, <% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>, the first line

②, <%session.codepage= "65001"%>, suggest the second line

③, <meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 "/>,head District
Step One: Modify the commond.asp file to replace the first 4 lines of the file, that is, the code in front of the ' Define Cookie,application field ' with the following code:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
Option Explicit
Response.Buffer = True
Server.ScriptTimeout = 90
session.codepage=936


The reference is:
If you make a Web page script that is different from the default code page on the Web service side, you must indicate the code page:
codepage=936 Simplified Chinese GBK
codepage=950 Traditional Chinese BIG5
codepage=437 American/Canadian English
codepage=932 Japanese
codepage=949 Han Wen
codepage=866 Russian
codepage=65001 Unicode UFT-8

Step two: Put all the


<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>


Change into


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>


and save as ANSI


The method of converting GB2312 to UTF-8 encoding

First step:
Modify the commond.asp file to replace the first 4 lines of the file, that is, the code in front of the definition cookie,application field with the following code:

Program code:

<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<%
Option Explicit
Response.buffer=true
session.codepage=65001
Server.ScriptTimeout = 90


Then modify header.asp and admincp.asp and attachment.asp files to find:

Program code:

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>


Modified to:

Program code:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>


Step Two:
Will blog all ASP and JS files, open with Notepad, and then save as, encoding is the default, the choice into UTF-8 on the

Transferred from: http://www.25175.com/200609/25175/25175_html/2009-04/2987.html

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.