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

2018-09-06 11:22

阅读:443

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

<%
OptionExplicit

FunctionstripHTML(strHTML)
StripstheHTMLtagsfromstrHTML

DimobjRegExp,strOutput
SetobjRegExp=NewRegexp

objRegExp.IgnoreCase=True
objRegExp.Global=True
objRegExp.Pattern=<.+?>

ReplaceallHTMLtagmatcheswiththeemptystring
strOutput=objRegExp.Replace(strHTML,)

Replaceall<and>with<and>
strOutput=Replace(strOutput,<,<)
strOutput=Replace(strOutput,>,>)

stripHTML=strOutputReturnthevalueofstrOutput

SetobjRegExp=Nothing
EndFunction


%>

<formmethod=postid=form1name=form1>
<b>EnteranHTMLString:</b><br>
<textareaname=txtHTMLcols=50rows=8wrap=virtual><%=Request(txtHTML)%></textarea>
<p>
<inputtype=submitvalue=StripHTMLTags!id=submit1name=submit1>
</form>

<%ifLen(Request(txtHTML))>0then%>
<p><hr><p>
<b><u>Viewofstring<i>withno</i>HTMLstripping:</u></b><br>
<xmp>
<%=Request(txtHTML)%>
</xmp><p>
<b><u>Viewofstring<i>with</i>HTMLstripping:</u></b><br>
<pre>
<%=StripHTML(Request(txtHTML))%>
</pre>
<%EndIf%>


评论


亲,登录后才可以留言!