我的用户将阿拉伯语报纸中的阿拉伯语文本复制并粘贴到文本区域。 我希望能够存储阿拉伯语中的char代码,例如& #1500; &安培; #1501;等等。我怎么做?
当我使用以下代码段时,我最终得错了数字...... 首先,我转换为数字的每个字符最终为3位数,而我知道阿拉伯字符代码实体是4位数。
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!
答案 0 :(得分:1)
这就是我的意思。切换所有内容以使用UTF-8。确保发布表单的页面与Response.CharSet = "UTF-8"
及其Response.CodePage = 65001
一起发送。它们与接收页面相同吗?现在,无论使用何种语言,您都不需要做任何事情。
答案 1 :(得分:0)
好吧,我整理了一下。只需使用我放在下面的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