php专区

 首页 > php专区 > 正则表达式 > 用正则表达式过滤html代码_正则表达式

用正则表达式过滤html代码_正则表达式

分享到:
【字体:
导读:
         [导读] 用正则表达式过滤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 < and >
 strOutput = Replace(strOutput, "<", "<")
 strOutput = Replace(strOutput, ">", ">")

 stripHTML = strOutput 'Return the value of strOutput

 Set objRegExp = Nothing
End Function
%>


 Enter an HTML String:

 
 


 

<% if Len(Request("txtHTML")) > 0 then %>
 



 View of string with no HTML stripping:

 

<br> <%=Request("txtHTML")%><br> 


 View of string with HTML stripping:

 


 <%=StripHTML(Request("txtHTML"))%>
 

<% End If %>

分享到:
ubb js_正则表达式
strIcons = "1"  //允许笑脸转换strSmile="1"   //同上ImgName="em"picurl="/images/emot/" function UBBCode(content,html){    content=content.replace("\\r","");    content=content.replace("\\n","");    return (trans(content));} function trans(strContent){    var re;  re=/\[IMG\](.+?)\...
个人理解正则表达式——懒惰匹配 问题...
问题描述 本文链接:http://www.hcoding.com/?p=130 初学正则表达式的时候都有一个疑问,例如:需要匹配串 "_abc_123_" 中 第一对"_"之间的字符,刚开始学习正则表达式的时候会写成 "/_\w*_/",匹配的结果就是"abc_123" 而不是"abc"了;大神说加上一个问号,"/_\w*?_/",这时候匹配的结果就是"abc"。 我们知道&...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……