asp下实现对HTML代码进行转换的函数
程序员文章站
2023-01-24 23:23:05
<% '****************************** '函数:htmlencode(restring) '参数:restring,待编码转换处理的字符...
<%
'******************************
'函数:htmlencode(restring)
'参数:restring,待编码转换处理的字符串
'作者:阿里西西
'日期:2007/7/15
'描述:对html代码进行转换
'示例:htmlencode("<p>欢迎访问<br>阿里西西</p>")
'******************************
function htmlencode(restring)
dim str:str=restring
if not isnull(str) then
str = uncheckstr(str)
str = replace(str, "&", "&")
str = replace(str, ">", ">")
str = replace(str, "<", "<")
str = replace(str, chr(32), " ")
str = replace(str, chr(9), " ")
str = replace(str, chr(9), " ")
str = replace(str, chr(34), """)
str = replace(str, chr(39), "'")
str = replace(str, chr(13), "")
str = replace(str, chr(10), "<br>")
htmlencode = str
end if
end function
'反转换html代码
function htmldecode(restring)
dim str:str=restring
if not isnull(str) then
str = replace(str, "&", "&")
str = replace(str, ">", ">")
str = replace(str, "<", "<")
str = replace(str, " ", chr(32))
str = replace(str, " ", chr(9))
str = replace(str, " ", chr(9))
str = replace(str, """, chr(34))
str = replace(str, "'", chr(39))
str = replace(str, "", chr(13))
str = replace(str, "<br>", chr(10))
htmldecode = str
end if
end function
%>
'******************************
'函数:htmlencode(restring)
'参数:restring,待编码转换处理的字符串
'作者:阿里西西
'日期:2007/7/15
'描述:对html代码进行转换
'示例:htmlencode("<p>欢迎访问<br>阿里西西</p>")
'******************************
function htmlencode(restring)
dim str:str=restring
if not isnull(str) then
str = uncheckstr(str)
str = replace(str, "&", "&")
str = replace(str, ">", ">")
str = replace(str, "<", "<")
str = replace(str, chr(32), " ")
str = replace(str, chr(9), " ")
str = replace(str, chr(9), " ")
str = replace(str, chr(34), """)
str = replace(str, chr(39), "'")
str = replace(str, chr(13), "")
str = replace(str, chr(10), "<br>")
htmlencode = str
end if
end function
'反转换html代码
function htmldecode(restring)
dim str:str=restring
if not isnull(str) then
str = replace(str, "&", "&")
str = replace(str, ">", ">")
str = replace(str, "<", "<")
str = replace(str, " ", chr(32))
str = replace(str, " ", chr(9))
str = replace(str, " ", chr(9))
str = replace(str, """, chr(34))
str = replace(str, "'", chr(39))
str = replace(str, "", chr(13))
str = replace(str, "<br>", chr(10))
htmldecode = str
end if
end function
%>