Solution to the garbled problem of UTF-8 and gb2312 encoding conversion in ASP

Source: Internet
Author: User

Currently, blog programs are generally UTF-8 encoded. To add other programs to the website, if it is not UTF-8 but gb2312, it is easy to see garbled characters when opening pages during page conversion, after searching for materials and testing, we can summarize the best method. First, let's take a look at the basic code:
<% @ CodePage = 65001%> UTF-8
<% @ CodePage = 936%> Simplified Chinese
<% @ CodePage = 950%> traditional Chinese
<% @ CodePage = 437%> American/Canadian English
<% @ CodePage = 932%> Japanese
<% @ CodePage = 949%> Korean
<% @ CodePage = 866%> Russian

CodePage specifies the encoding used by IIS to read passed strings (such as form submission and address bar transfer ). The cause of garbled characters is that the module encoding is different when the website is to be integrated. Just like my blog, integration will be out of this problem, because blog is Utf-8, recently many netizens are consulting for this problem, I tried a lot of methods. The most convenient method is as follows:
Do not convert any module page encoding the UTF-8 or UTF-8, The gb22312 or gb2312, In the Utf-8 module package file (such as Conn. ASP, but pay attention to Conn. ASP must be called in the first line .)
<% @ Language = "VBScript" codePage = "65001" %>
<% Session. codePage = 65001%>

Add
<% @ Language = "VBScript" codePage = "936" %>
<% Session. codePage = 936%>, and other codes.
If the data volume you are using is ms SQL, you need to remember the usage of chinese_prc_ci_as in both the internal and traditional environments.
 
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" %>
Last: Select encoded as UTF-8 when saving the file

 

The easiest way is to use NotePad to open and save the UFT-8...

Run the command again. Well, this time it is displayed normally ......
Conclusion: The use of UTF-8 encoding, in addition to saving the file as a UTF-8 format, also need to specify codePage and charset.
 
ASP + ACCESS + FSO + UTF-8, Chinese garbled solution notes
Some people say that they should not use FSO to read and write files, replace it with ADODB. Stream, and use. charset = "UTF-8" to avoid garbled characters. But I am still garbled, and it seems that this is not the best way.
Powered by 25175.net
 
My solution is to add this sentence: Session. codePage = "65001" (once used, it will be OK, and then (restart once) It will not be garbled. What's the problem ?)
 
Summary:
 
1. All files are saved in UTF-8 format;
 
2. Add the following three lines of code to the ASP file:
 
① <% @ Language = "VBScript" codePage = "65001" %>, first line
 
② <% Session. codePage = "65001" %>. The second line is recommended.
 
③ <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>, head area
 
Step 1: Modify the commond. asp file and replace the code before the application domain with the following code: powered by 25175.net
<% @ Language = "VBScript" codePage = "936" %>
<%
Option explicit
Response. Buffer = true
Server. scripttimeout = 90
Session. codePage = 936

Reference:
If the webpage script is different from the default code page of the web server, you must specify the code page:
CodePage = 936 Simplified Chinese GBK
CodePage = 950 traditional Chinese big5
CodePage = 437 US/Canada English
CodePage = 932 Japanese
CodePage = 949 Korean
CodePage = 866 Russian
CodePage = 65001 Unicode UFT-8
Step 2: Set all

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>

Change

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>

Save it as ANSI

The method of converting gb2312 to UTF-8 Encoding
Step 1:
Modify the commond. asp file and replace the code before the application domain with the following code:
Program code:
<% @ Language = "VBScript" codePage = "65001" %>
<%
Option explicit
Response. Buffer = true
Session. codePage = 65001
Server. scripttimeout = 90

Modify header. asp and admincp. asp and the attachment. asp file to find:
Program code:
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>

To:
Program code:
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>

Step 2:
All ASP and JS files of blog, open with notepad, and then save as, encoding is the default, select to UTF-8 can be

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.