Web language coding and ASP garbled problem solution _ Application Skills

Source: Internet
Author: User
Recently, the company has a Japanese project, because the previous use of their own development of the Chinese CMS, and did not separate the language pack, in the construction of the site debugging process has been a headache garbled problem.

The reason of garbled appearance

Because each character encoding storage space is not the same, so when the use of different characters to read data, when the character space is too small, can not display the normal.

For example, the character set of Chinese characters is generally gb2312, if you use Utf-8 force to read the gb2312 characters, it may appear garbled. Because Utf-8 's character set storage space is greater than gb2312, when the use of Utf-8 read, some characters gb2312 encoding is not present, the characters do not exist will naturally appear garbled. For static files, if the file's storage Code and Web page encoding settings (charset) inconsistent, because of the above reasons will appear garbled problem.

The above is a simple analysis of the garbled problem, in the solution of existing problems have involved the ASP's support for internationalization.

Three functions involved: @CODEPAGE, Response.codepage,session.codepage

The following is a passage from MSDN.

Setting @CODEPAGE explicitly affects literal strings in a single response. Response.CodePage affects dynamic strings in a single Response, and Session.CodePage affects dynamic strings in all Respon SES in a session.

These three functions can be set up by ASP encoding, which @CODEPAGE equivalent to the header in PHP, must be issued at the beginning of the document.

In the Chinese operating system IIS, the default is gb2312, the parameter value is: "936″, and Japanese need to specify document codepage:

<%@ codepage=932%>

We use this function to set the document encoding specific use of the method can be referred to: http://www.cloudward.net/techLife/article.asp?id=490

Should there be no more problems now? Wow, the problem still exists. Consider the SEO company's ASP program all need to generate static pages. The resulting page is all Windows default ANSI, which contains the Japanese characters that still appear garbled. So we need an ASP function to generate utf-8 or Japanese-encoded files. We use the following code to complete:

Set objstream = Server.CreateObject ("ADODB. Stream ")
With Objstream
. Open
. Charset = "utf-8″//encoding, where you can change to any encoding
. Position = Objstream.size
. Writetext=pencat//pencat for written data
. SaveToFile Server.MapPath ("patch/flilename.html"), 2//Generate file path
. Close
End With
Set objstream = Nothing

After the test garbled problem solved.

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.