用正則表達式寫的HTML分離函數(shù)
更新時間:2007年03月16日 00:00:00 作者:
存成.asp文件,執(zhí)行,你用ASPHTTP抓內(nèi)容的時候用這個很爽,當(dāng)然自己要改進一下了
<%
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 %>
<%
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 %>
相關(guān)文章
[ASP]RegExp對象提供簡單的正則表達式支持功能使用說明
[ASP]RegExp對象提供簡單的正則表達式支持功能使用說明...2007-07-07
通過Response.Flush()實現(xiàn)下載失敗的解決方法
Response.Flush()實現(xiàn)對服務(wù)端文件的下載時,會失敗,不能正常彈出IE下載框,通過測試發(fā)現(xiàn)時瀏覽器的安全設(shè)置問題,如下操作便可解決2013-08-08
JScript中調(diào)用ActiveX獲取訪客網(wǎng)卡MAC地址實現(xiàn)代碼
這篇文章主要介紹了JScript中調(diào)用ActiveX獲取訪客網(wǎng)卡MAC地址實現(xiàn)代碼,注意本文代碼只適應(yīng)運行在IE瀏覽器上,需要的朋友可以參考下2014-08-08
忠網(wǎng)廣告 系統(tǒng) 用到的幾個函數(shù)
忠網(wǎng)廣告 系統(tǒng) 用到的幾個函數(shù)...2006-11-11

