用正则表达式过滤html代码

2025-05-29 0 65

代码例子如下:

  1. <%
  2. OptionExplicit
  3. FunctionstripHTML(strHTML)
  4. 'StripstheHTMLtagsfromstrHTML
  5. DimobjRegExp,strOutput
  6. SetobjRegExp=NewRegexp
  7. objRegExp.IgnoreCase=True
  8. objRegExp.Global=True
  9. objRegExp.Pattern="<.+?>"
  10. 'ReplaceallHTMLtagmatcheswiththeemptystring
  11. strOutput=objRegExp.Replace(strHTML,"")
  12. 'Replaceall<and>with&lt;and&gt;
  13. strOutput=Replace(strOutput,"<","&lt;")
  14. strOutput=Replace(strOutput,">","&gt;")
  15. stripHTML=strOutput'ReturnthevalueofstrOutput
  16. SetobjRegExp=Nothing
  17. EndFunction
  18. %>
  19. <formmethod="post"id=form1name=form1>
  20. <b>EnteranHTMLString:</b><br>
  21. <textareaname="txtHTML"cols="50"rows="8"wrap="virtual"><%=Request("txtHTML")%></textarea>
  22. <p>
  23. <inputtype="submit"value="StripHTMLTags!"id=submit1name=submit1>
  24. </form>
  25. <%ifLen(Request("txtHTML"))>0then%>
  26. <p><hr><p>
  27. <b><u>Viewofstring<i>withno</i>HTMLstripping:</u></b><br>
  28. <xmp>
  29. <%=Request("txtHTML")%>
  30. </xmp><p>
  31. <b><u>Viewofstring<i>with</i>HTMLstripping:</u></b><br>
  32. <pre>
  33. <%=StripHTML(Request("txtHTML"))%>
  34. </pre>
  35. <%EndIf%>
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 用正则表达式过滤html代码 https://www.kuaiidc.com/88863.html

相关文章

发表评论
暂无评论