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