用正则表达式过滤html代码
代码例子如下:
%
Option ExplicIT
Function stripHTML(strHTML)
'Strips the HTML tags From strHTML
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = ".+?>
"
'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, "")
'Replace all and >
with &
lt;
and &
gt;
strOutput = Replace(strOutput, "", "&
lt;
")
strOutput = Replace(strOutput, ">
", "&
gt;
")
stripHTML = strOutput 'Return the value of strOutput
Set objRegExp = Nothing
End Function
%>
form method="post" id=form1 name=form1>
b>
Enter an HTML String:/b>
br>
textarea name="txtHTML" cols="50" rows="8" wrap="virtual">
%=Request("txtHTML")%>
/textarea>
p>
input tyPE="submit" value="Strip HTML Tags!" id=submit1 name=submit1>
/form>
% if Len(Request("txtHTML")) >
0 then %>
p>
hr>
p>
b>
u>
View of string i>
with no/i>
HTML stripping:/u>
/b>
br>
XMp>
%=Request("txtHTML")%>
/xmp>
p>
b>
u>
View of string i>
with/i>
HTML stripping:/u>
/b>
br>
PRe>
%=StripHTML(Request("txtHTML"))%>
/pre>
% End If %>
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 用正则表达式过滤html代码
本文地址: https://pptw.com/jishu/595405.html