ASP UTF-8 page garbled +gb2312 turn UTF-8 + generate UTF-8 file (code) 1th/2 page _ Application Tips

Source: Internet
Author: User
Tags documentation
The best way:
Let's say something basic:
<%@ Codepage=65001%>utf-8
<%@ codepage=936%> Simplified Chinese
<%@ codepage=950%> Traditional Chinese
<%@ codepage=437%> American/Canadian English
<%@ codepage=932%> Japanese
<%@ codepage=949%> Han Wen
<%@ codepage=866%> Russian

CODEPAGE specifies what IIS encodes to read the string passed over (form submission, address bar delivery, etc.).

The reason for the garbled is that the site should be integrated when the module coding is not the same.
As my blog is the same, the integration of the time will be the problem, because the blog is Utf-8,
Recently many netizens are consulting for this problem, I have tried many ways.
The most convenient methods are 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 documentation (such as conn.asp, but be aware that conn.asp must be called on the first line) plus the front
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<%Session.CodePage=65001%>
At the top of the package documentation for the GB2312 module, add
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%Session.CodePage=936%>
Analogy to other encodings.
the conversion between Chinese characters and UTF-8 in ASP
' ============= Kanji conversion to utf-8==================

function Chinese2unicode (STR)
For I=1 to Len (STR)
Str_one=mid (str,i,1)
STR_UNICODE=STR_UNICODE&AMP;CHR (38)
STR_UNICODE=STR_UNICODE&AMP;CHR (35)
STR_UNICODE=STR_UNICODE&AMP;CHR (120)
str_unicode=str_unicode& Hex (AscW (Str_one))
STR_UNICODE=STR_UNICODE&AMP;CHR (59)
Next
Chinese2unicode = Str_unicode
End Function



' =============utf-8 conversion to Chinese characters ==================

function UTF2GB (UTFSTR)
For Dig=1 to Len (UTFSTR)
If mid (utfstr,dig,1) = "%" Then
If Len (utfstr) >= dig+8 Then
Gbstr=gbstr & Convchinese (Mid (utfstr,dig,9))
Dig=dig+8
Else
Gbstr=gbstr & Mid (utfstr,dig,1)
End If
Else
Gbstr=gbstr & Mid (utfstr,dig,1)
End If
Next
Utf2gb=gbstr
End Function


function Convchinese (x)
A=split (Mid (x,2), "%")
I=0
J=0

For i=0 to UBound (A)
A (i) =c16to2 (A (i))
Next

For i=0 to UBound (A)-1
Digs=instr (A (i), "0")
Unicode= ""
For J=1 to DigS-1
If J=1 Then
A (i) =right (A (i), Len (A (i))-digs)
Unicode=unicode & A (i)
Else
I=i+1
A (i) =right (A (i), Len (A (i))-2)
Unicode=unicode & A (i)
End If
Next

If Len (c2to16 (Unicode)) =4 Then
Convchinese=convchinese & ChrW (int ("&h" & C2to16 (Unicode))
Else
Convchinese=convchinese & chr (int ("&h" & C2to16 (Unicode))
End If
Next
End Function

function c2to16 (x)
I=1
For I=1 to Len (x) Step 4
C2to16=c2to16 & Hex (C2to10 (Mid (x,i,4)))
Next
End Function

function C2to10 (x)
C2to10=0
If x= "0" Then Exit function
I=0
For i= 0 to Len (x)-1
If Mid (X,len (x)-i,1) = "1" then c2to10=c2to10+2^ (i)
Next
End Function

function C16to2 (x)
I=0
For I=1 to Len (Trim (x))
Tempstr= C10to2 (CInt (int ("&h" & Mid (x,i,1)))
Do While Len (TEMPSTR) <4
Tempstr= "0" & TempStr
Loop
C16to2=c16to2 & TempStr
Next
End Function

function C10to2 (x)
MYSIGN=SGN (x)
X=abs (x)
Digs=1
Todo
If X<2^digs Then
Exit Do
Else
Digs=digs+1
End If
Loop
Tempnum=x

I=0
For I=digs to 1 step-1
If tempnum>=2^ (i-1) Then
tempnum=tempnum-2^ (i-1)
C10to2=c10to2 & "1"
Else
C10to2=c10to2 & "0"
End If
Next
If Mysign=-1 then c10to2= "-" & C10to2
End Function

GB2312 Turn UTF-8

' Personal Code style note (the first lowercase alphabet in the variable name represents the variable type)
' I: an integer type;
' s: string;
Function U2utf8 (Byval a_inum)
Dim Sresult,sutf8
Dim Itemp,ihexnum,i

Ihexnum = Trim (a_inum)

If ihexnum = "" Then
Exit Function
End If

Sresult = ""

If (Ihexnum < 128) Then
Sresult = Sresult & Ihexnum
ElseIf (Ihexnum < 2048) Then
Sresult = ChrB (&h80 + (Ihexnum and &h3f))
Ihexnum = ihexnum \ &h40
Sresult = ChrB (&hc0 + ihexnum and &h1f)) & Sresult
ElseIf (Ihexnum < 65536) Then
Sresult = ChrB (&h80 + (Ihexnum and &h3f))
Ihexnum = ihexnum \ &h40
Sresult = ChrB (&h80 + ihexnum and &h3f)) & Sresult
Ihexnum = ihexnum \ &h40
Sresult = ChrB (&he0 + ihexnum and &AMP;HF)) & Sresult
End If

U2utf8 = Sresult
End Function

Function Gb2utf (Byval a_sstr)
Dim sgb,sresult,stemp
Dim Ilen,iunicode,itemp,i

SGB = Trim (A_SSTR)
Ilen = Len (SGB)
For i = 1 to Ilen
Stemp = Mid (sgb,i,1)
itemp = ASC (stemp)

If (itemp>127 OR itemp<0) Then
Iunicode = AscW (stemp)
If iunicode<0 Then
Iunicode = Iunicode + 65536
End If
Else
Iunicode = itemp
End If

Sresult = Sresult & U2utf8 (Iunicode)
Next

Gb2utf = Sresult
End Function

' Invoke method
Response.BinaryWrite (Gb2utf ("Chinese"))
current 1/2 page   1 2 Next read the full text
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.