• 主页

# 替换问题

aoenzh 2004-04-05 09:06:50

...全文
6 点赞 收藏 6

6 条回复

aoenzh 2004-04-05

xumail(笑傲江湖) 的方法最简单，最实用

xumail 2004-04-05

mikespook 2004-04-05
<%
function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"<"
case ">"
result=result+">"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"""
case "&"
result=result+"&"
case chr(32)
'result=result+" "
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case chr(9)
result=result+" "
case "'"
result=result+"´"
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
%>

cjf1009 2004-04-05

function HTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")

fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")

HTMLEncode = fString
end if
end function

<%=HTMLEncode(str)%>

ASP

2.8w+

ASP即Active Server Pages，是Microsoft公司开发的服务器端脚本环境。