手机
当前位置:查字典教程网 >网页设计 >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实现用户注册自动校验功能实例代码

推荐WEB开发者最佳HTML5和CSS3代码生成器

HTML5样式控制示例代码

html5 获取input内容

移动web模拟客户端实现多方框输入密码效果【附代码】

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

html5弹跳球示例代码

精品推荐
分类导航