Asp classic 阿拉伯语似乎乱七八糟
我的用户将阿拉伯语报纸上的阿拉伯语文本复制并粘贴到文本区。 我希望能够以字符编码的形式存储阿拉伯语,例如ל;ם 等等我该怎么做 当我使用下面的代码片段时,我最终得到了错误的数字。。。 首先,我转换成数字的每个字符最后都是3位数字,而我知道阿拉伯字符代码实体是4位数字Asp classic 阿拉伯语似乎乱七八糟,asp-classic,character-encoding,ascii,arabic,Asp Classic,Character Encoding,Ascii,Arabic,我的用户将阿拉伯语报纸上的阿拉伯语文本复制并粘贴到文本区。 我希望能够以字符编码的形式存储阿拉伯语,例如ל;ם 等等我该怎么做 当我使用下面的代码片段时,我最终得到了错误的数字。。。 首先,我转换成数字的每个字符最后都是3位数字,而我知道阿拉伯字符代码实体是4位数字 IncomingArabic = request("IncomingArabic") MaxLen = Len(IncomingArabic) For i = 1 To MaxLen curCha
IncomingArabic = request("IncomingArabic")
MaxLen = Len(IncomingArabic)
For i = 1 To MaxLen
curChar = Mid(IncomingArabic, lLoop, 1)
''# curChar is an arabic char
iChr = Asc(curChar) ''# this gives me a 3 digit! And when I tried HEX(curChar) here, it gave a type mismatch error.
Encoded = Encoded & "&#" & iChr & ";"
Next
Response.write Encoded ''# shows gibberish!
好吧,我搞定了。只需使用我放在下面的Arabize函数
''# example usage
response.write Arabize(request("IncomingArabic")) //gives you the correct 4 digit sequence!
Function Arabize(Str)
Dim Bytes
dim FromCharset, ToCharset
FromCharset = "windows-1256"
ToCharset = "windows-1256"
Bytes = StringToBytes(Str, FromCharset)
dim temp
temp = BytesToString(Bytes, ToCharset)
Arabize = server.htmlencode(temp)
End Function
''# you are gonna need the rest too...
Const adTypeBinary = 1
Const adTypeText = 2
''# accept a string and convert it to Bytes array in the selected Charset
Function StringToBytes(Str,Charset)
Dim Stream : Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Type = adTypeText
Stream.Charset = Charset
Stream.Open
Stream.WriteText Str
Stream.Flush
Stream.Position = 0
''# rewind stream and read Bytes
Stream.Type = adTypeBinary
StringToBytes= Stream.Read
Stream.Close
Set Stream = Nothing
End Function
''# accept Bytes array and convert it to a string using the selected charset
Function BytesToString(Bytes, Charset)
Dim Stream : Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Charset = Charset
Stream.Type = adTypeBinary
Stream.Open
Stream.Write Bytes
Stream.Flush
Stream.Position = 0
''# rewind stream and read text
Stream.Type = adTypeText
BytesToString= Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
好吧,我搞定了。只需使用我放在下面的Arabize函数
''# example usage
response.write Arabize(request("IncomingArabic")) //gives you the correct 4 digit sequence!
Function Arabize(Str)
Dim Bytes
dim FromCharset, ToCharset
FromCharset = "windows-1256"
ToCharset = "windows-1256"
Bytes = StringToBytes(Str, FromCharset)
dim temp
temp = BytesToString(Bytes, ToCharset)
Arabize = server.htmlencode(temp)
End Function
''# you are gonna need the rest too...
Const adTypeBinary = 1
Const adTypeText = 2
''# accept a string and convert it to Bytes array in the selected Charset
Function StringToBytes(Str,Charset)
Dim Stream : Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Type = adTypeText
Stream.Charset = Charset
Stream.Open
Stream.WriteText Str
Stream.Flush
Stream.Position = 0
''# rewind stream and read Bytes
Stream.Type = adTypeBinary
StringToBytes= Stream.Read
Stream.Close
Set Stream = Nothing
End Function
''# accept Bytes array and convert it to a string using the selected charset
Function BytesToString(Bytes, Charset)
Dim Stream : Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Charset = Charset
Stream.Type = adTypeBinary
Stream.Open
Stream.Write Bytes
Stream.Flush
Stream.Position = 0
''# rewind stream and read text
Stream.Type = adTypeText
BytesToString= Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
这是我想要的。将所有内容切换为使用UTF-8。确保发送该表单的页面时带有
Response.CharSet=“UTF-8”
及其Response.CodePage=65001
。对接收页面执行相同的操作。现在,无论使用哪种语言,你都不必再胡闹了。以下是我想要的。将所有内容切换为使用UTF-8。确保发送该表单的页面时带有Response.CharSet=“UTF-8”
及其Response.CodePage=65001
。对接收页面执行相同的操作。现在,无论使用哪种语言,您都不需要做任何事情。如果我这样做:y=BytesToString(StringToBytes(x,“Windows-1256”),“Windows-1256”)
为什么x
与y
不一样?如果它们是相同的,为什么不简单地执行:response.write Server.HtmlEncode(Request.Form(“IncomingArabic”)
?最奇怪的事情发生了。第二天,胡言乱语又回来了。我尝试了一切(包括你的建议)。然后我开始剪切代码以找到杯子在哪里。当我发现它在最意想不到的地方时,我感到震惊。当我移除设置utf-8的meta标记时,问题就消失了!难以置信的现在完全可以用了。工作解决方案非常简单,因为它现在可以得到原因,在html头上没有utf-8,在asp端没有设置代码页和字符集。utf-8到底是怎么引起我两天的麻烦的?我不知道。也许我对这个问题的回答:可能会提供一些见解。我读了你的精彩答案并投了赞成票。为什么当我删除了utf8和所有response.charset/和codepage的内容时,你认为整个事情开始运行良好?你的问题中缺少太多的因素,无法确定。关键是确保在访问表单值之前将响应代码页设置为65001,并确保发送表单以UTF-8编码发送。你在用什么浏览器进行测试?如果我这样做:y=BytesToString(StringToBytes(x,“Windows-1256”),“Windows-1256”)
为什么x
与y
不同?如果它们是相同的,为什么不简单地执行:response.write Server.HtmlEncode(Request.Form(“IncomingArabic”)
?最奇怪的事情发生了。第二天,胡言乱语又回来了。我尝试了一切(包括你的建议)。然后我开始剪切代码以找到杯子在哪里。当我发现它在最意想不到的地方时,我感到震惊。当我移除设置utf-8的meta标记时,问题就消失了!难以置信的现在完全可以用了。工作解决方案非常简单,因为它现在可以得到原因,在html头上没有utf-8,在asp端没有设置代码页和字符集。utf-8到底是怎么引起我两天的麻烦的?我不知道。也许我对这个问题的回答:可能会提供一些见解。我读了你的精彩答案并投了赞成票。为什么当我删除了utf8和所有response.charset/和codepage的内容时,你认为整个事情开始运行良好?你的问题中缺少太多的因素,无法确定。关键是确保在访问表单值之前将响应代码页设置为65001,并确保发送表单以UTF-8编码发送。您正在使用哪些浏览器进行测试?您是否尝试了AscW
而不是Asc
?您是否尝试了AscW
而不是Asc
?