过滤字符串Str中的HTML代码

      ASP与ASP.NET 2005-4-19 0:44
<%
'过滤字符串Str中的HTML代码
Public Function FilterHtml(Str)
If Trim(Str) = "" Or IsNull(Str) Then
FilterHtml=""
Else
Str = Replace(Str, ">", "&gt;")
Str = Replace(Str, "<", "&lt;")
Str = Replace(Str, Chr(32), "&nbsp;")
Str = Replace(Str ,Chr(9), "&nbsp;")
Str = Replace(Str, Chr(34), "&quot;")
Str = Replace(Str, Chr(39), "&#39;")
Str = Replace(Str, Chr(13), "")
Str = Replace(Str, Chr(10) & Chr(10), "</p><p>")
Str = Replace(Str, Chr(10), "<br> ")
FilterHtml = Str
End If
End Function
%>
<form name="form1" method="post" action="">
输入字符串:
<input name="text" type="text" id="text" >
<input type="submit" name="Submit" value="提交">
</form>
<%
Dim X
X=Request.Form("text")
If X<>"" Then
%>
<p>输入的字符串为:<%=X%></p>
<p>过滤HTML代码后的字符串为:<%=FilterHtml(X)%></p>
<%
End If
%>
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}