cha.asp网页代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
dim yname
yname=request.querystring("name")
%>
<%
'转码过程
Function UTF2GB(s)
Dim sm
Set sm = Server.CreateObject("ADODB.Stream")
With sm
.Type = 2
.Mode = 3
.Open
.CharSet = "GB2312"
.WriteText UnEscape(s)
.Position = 0
.CharSet = "UTF-8"
UTF2GB = .ReadText(-1)
.Close
End With
Set sm = Nothing
End Function
%>
<%
dim yname2
yname2=UTF2GB(yname)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><%=yname2%></title>
</head>
<body>
<table border="0">
<tr>
<td ><%=yname2%>资讯</td>
</tr>
</table>
</body>
</html>
上面最终得到 yname2这个简体中文参数,但只能截取两个汉字,字数多于两个后,后面的就截取不到了!
求高手帮助修改代码!
3 个解决方案
#1
test.asp
测试:
test.asp?p1=呼和浩特&p2=%E5%91%BC%E5%92%8C%E6%B5%A9%E7%89%B9&p3=%BA%F4%BA%CD%BA%C6%CC%D8
<%
Function param(name)
Response.CodePage = 28591
param = Request.Item(name).Item & ""
Response.CodePage = 936
Dim cSet : cSet = "GBK"
With New RegExp
.Pattern = "^(?:[\x00-\x7f]|[\xe0-\xef][\x80-\xbf]{2})+$"
If .Test(param) Then cSet = "UTF-8"
End With
With Server.CreateObject("ADODB.Stream")
.Type = 2
.Charset = "iso-8859-1"
.Open
.WriteText param
.Position = 0
.Charset = cSet
param = .ReadText(-1)
.Close
End With
End Function
Response.Write param("p1") & "<br/>"
Response.Write param("p2") & "<br/>"
Response.Write param("p3") & "<br/>"
%>
测试:
test.asp?p1=呼和浩特&p2=%E5%91%BC%E5%92%8C%E6%B5%A9%E7%89%B9&p3=%BA%F4%BA%CD%BA%C6%CC%D8
#2
这样不知道行不,呵呵...
先把页面编码转成UTF-8,然后获取name,然后把页面转会GBK
Session.CodePage=65001
namestr=request("name")
Session.CodePage=936
先把页面编码转成UTF-8,然后获取name,然后把页面转会GBK
Session.CodePage=65001
namestr=request("name")
Session.CodePage=936
#3
第一个Session.CodePage设置之后,只要触发了取值,所有Request参数都会转为Session.CodePage对应的编码,再改回来也没用
#1
test.asp
测试:
test.asp?p1=呼和浩特&p2=%E5%91%BC%E5%92%8C%E6%B5%A9%E7%89%B9&p3=%BA%F4%BA%CD%BA%C6%CC%D8
<%
Function param(name)
Response.CodePage = 28591
param = Request.Item(name).Item & ""
Response.CodePage = 936
Dim cSet : cSet = "GBK"
With New RegExp
.Pattern = "^(?:[\x00-\x7f]|[\xe0-\xef][\x80-\xbf]{2})+$"
If .Test(param) Then cSet = "UTF-8"
End With
With Server.CreateObject("ADODB.Stream")
.Type = 2
.Charset = "iso-8859-1"
.Open
.WriteText param
.Position = 0
.Charset = cSet
param = .ReadText(-1)
.Close
End With
End Function
Response.Write param("p1") & "<br/>"
Response.Write param("p2") & "<br/>"
Response.Write param("p3") & "<br/>"
%>
测试:
test.asp?p1=呼和浩特&p2=%E5%91%BC%E5%92%8C%E6%B5%A9%E7%89%B9&p3=%BA%F4%BA%CD%BA%C6%CC%D8
#2
这样不知道行不,呵呵...
先把页面编码转成UTF-8,然后获取name,然后把页面转会GBK
Session.CodePage=65001
namestr=request("name")
Session.CodePage=936
先把页面编码转成UTF-8,然后获取name,然后把页面转会GBK
Session.CodePage=65001
namestr=request("name")
Session.CodePage=936
#3
第一个Session.CodePage设置之后,只要触发了取值,所有Request参数都会转为Session.CodePage对应的编码,再改回来也没用