Sometimes we cannot control the emergence of garbled code. For example, when sending mail, some emails display garbled code. For example, AJAX return data is always garbled. What should I do?
A few days ago, I encountered the form of submitting the form with AJAX, and then sent the email. So I wrote the following two functions to solve these two problems.
The first function converts the data in HTML to the HTML entity, while the HTML tag does not turn automatically. This will not be garbled no matter wherever it goes. You can choose to send HTML format emails when sending emails.
The second function also replaced the JS data with a transition character. It also avoided the conversion of characters such as JavaScript keywords. No matter what the webpage is, it will not be garbled.
Function HTMLENTIES (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 the test = right (0000 ″ & test, 4)
Str = Str & /U & Temp
Next
Unicode = STR
End function
If you are holding the attitude of holding it, you can use anything or not. Of course It is the ASCW (CHAR) function that may return long integer values, and ASP treats it as a integer, and requires some small processing.