Recently, the company has a Japanese project. Because we used our own Chinese CMS and did not separate the Language Pack, we encountered a headache During website construction and debugging.
Causes of garbled characters
Because the storage space of character encoding is different, when data is read using different characters, when the character space is too small, it cannot be displayed normally.
For example, the character set of Chinese characters is generally gb2312. If UTF-8 is used to forcibly read and change the character set of gb2312, garbled characters may occur. Because the storage space of the UTF-8 character set is larger than that of gb2312, when UTF-8 is used for reading, the encoding of some characters gb2312 does not exist, and non-existent characters will naturally be garbled. For static files, if the storage encoding of the files is inconsistent with the encoding settings (charset) in the webpage, garbled characters may occur due to the above reasons.
The above is a simple analysis of the garbled problem. When solving the existing problem, it involves ASP's support for internationalization.
Three functions are involved: @ codePage, response. codePage, and session. codePage.
The following is a passage in 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 responses in a session.
All three functions can be encoded with ASP. @ codePage is equivalent to the header in PHP and must be issued at the beginning of the document.
In IIS of the Chinese operating system, the default value is gb2312 and the parameter value is "936". In Japanese, you must specify the document codePage:
<% @ CodePage = 932%>
We use this function to set document encoding specific usage can refer to: http://www.cloudward.net/techLife/article.asp? Id = 490
Should it be okay now? Wow, the problem persists. Considering the SEO Company's ASPProgramAll static pages must be generated. The generated pages are all windows's default ANSI, and garbled characters are still contained in Japanese. In this way, we need an ASP function to generate UTF-8 or Japanese encoded files. We use the followingCodeCompleted:
Set objstream = server. Createobject ("ADODB. Stream ")
With objstream
. Open
. Charset = "UTF-8" // encoding. You can change it to any encoding here.
. Position = objstream. Size
. Writetext = pencat // pencat is the written data
. Savetofile server. mappath ("patch/flilename.html"), 2 // generate the file path
. Close
End
Set objstream = nothing
Solve the garbled problem after testing.