A few days ago, I encountered the situation of using Ajax to submit a form and then send an email. So I wrote the following two functions to solve these two problems.
The first function converts the data in HTML into HTML entities, and HTML tags are automatically not converted, so that no matter where they go, there will be no garbled characters. You can choose to send emails in HTML format when sending emails.
The second function also converts JS data into escape characters , also avoids the conversion of JS keywords and other characters, no matter what encoding the web page is, it will not be garbled. Without further ado, look at the code below.
Function htmlentities(str)
Dim a,i,char
For i = 1 to Len(str)
char = mid(str, i, 1)
a=Ascw(char)
If a > 128 Or a < 0 then
htmlentities = htmlentities & “” & clng(”&h” & hex((Ascw(char)))) & “;”
Else
htmlentities = htmlentities & char
End if
Next
End Function
Function Unicode( str1)
Dim str,temp
str = “”
For i=1 To Len(str1)
temp = Hex(AscW(Mid(str1,i,1)))
If len(temp) < 5 Then temp = Right(”0000″ & temp, 4)
str = str & “u” & temp
Next
Unicode = str
End Function
If you have the attitude of just taking it and using it, you can just use it without worrying about anything. Of course, many times we will rewrite some codes to meet the needs of special situations. If you are interested in studying and researching Attitude, then what needs to be noted here is that the Ascw(char) function may return a long integer value, and ASP treats it as an integer, and some minor processing is required.