手机
当前位置:查字典教程网 >网页设计 >HTML5教程 >用正则表达式过滤html代码
用正则表达式过滤html代码
摘要:代码例子如下:EnteranHTMLString:0then%>ViewofstringwithnoHTMLstripping:Viewof...

代码例子如下:
<%
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
%>

<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 %>

【用正则表达式过滤html代码】相关文章:

HTML5 用动画的表现形式装载图像

Html5实现用户注册自动校验功能实例代码

简单html5代码获取地理位置

简单html5代码获取地理位置

HTML5注册表单的自动聚焦与占位文本示例代码

基于HTML5 audio元素播放声音jQuery小插件

HTML5使用DOM进行自定义控制示例代码

使用html5 canvas 画时钟代码实例分享

关于HTML5你必须知道的28个新特性,新技巧以及新技术

HTML5调用手机摄像头拍照的实现思路及代码

精品推荐
分类导航