程序员

用正则表达式写的HTML分离函数

作者:admin 2021-08-16 我要评论

存成.asp文件,执行,你用ASPHTTP抓内容的时候用这个很爽,当然自己要改进一下了 % OptionExplicit FunctionstripHTML(strHTML) 'StripstheHTMLtagsfromstrHTML ...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
存成.asp文件,执行,你用ASPHTTP抓内容的时候用这个很爽,当然自己要改进一下了

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


原文链接:https://m.jb51.net/article/8564.htm

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 用正则表达式写的HTML分离函数

    用正则表达式写的HTML分离函数

  • asp中&quot;无限流&quot;分页

    asp中&quot;无限流&quot;分页

  • asp的一个日期格式化函数

    asp的一个日期格式化函数

  • asp中创建多级目录的两段代码

    asp中创建多级目录的两段代码

腾讯云代理商
精彩导读
海外云服务器
热门资讯
腾讯云代理商