Home > Web Front-end > JS Tutorial > body text

HTML data and JS data encoding function in ASP_javascript skills

WBOY
Release: 2016-05-16 18:42:05
Original
958 people have browsed it

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.

Copy code The code is as follows:

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.
Related labels:
asp
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!