去除HTML代碼中所有標(biāo)簽的兩種方法
更新時(shí)間:2007年08月08日 10:31:05 作者:
去除HTML代碼中所有標(biāo)簽
<%
'******************************
'函數(shù):RemoveHTML_A(strText)
'參數(shù):strText,待處理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除HTML代碼中所有標(biāo)簽
'示例:<%=RemoveHTML_A("<b>歡迎光臨阿里西西</b>")%>
'******************************
Function RemoveHTML_A(strText)
Dim nPos1
Dim nPos2
nPos1 = InStr(strText, "<")
Do While nPos1>0
nPos2 = InStr(nPos1+1, strText, ">")
If nPos2>0 Then
strText = Left(strText, nPos1 - 1) & Mid(strText, nPos2 + 1)
Else
Exit Do
End If
nPos1 = InStr(strText, "<")
Loop
RemoveHTML_A = strText
End Function
%>
去除HTML代碼中所有標(biāo)簽之二
<%
'******************************
'函數(shù):RemoveHTML_B(strText)
'參數(shù):strText,待處理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除HTML代碼中所有標(biāo)簽
'示例:<%=RemoveHTML_B("<b>歡迎光臨阿里西西</b>")%>
'******************************
Function RemoveHTML_B( strText )
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
RemoveHTML_B = RegEx.Replace(strText, "")
End Function
%>
去除HTML代碼中所有標(biāo)簽之三
<%
'******************************
'函數(shù):RemoveHTML_C(strText)
'參數(shù):strText,待處理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除HTML代碼中所有標(biāo)簽
'示例:<%=RemoveHTML_C("<b>歡迎光臨阿里西西</b>")%>
'******************************
Function RemoveHTML_C( strText )
Dim TAGLIST
TAGLIST = ";!--;!DOCTYPE;A;ACRONYM;ADDRESS;APPLET;AREA;B;BASE;BASEFONT;" &_
"BGSOUND;BIG;BLOCKQUOTE;BODY;BR;BUTTON;CAPTION;CENTER;CITE;CODE;" &_
"COL;COLGROUP;COMMENT;DD;DEL;DFN;DIR;DIV;DL;DT;EM;EMBED;FIELDSET;" &_
"FONT;FORM;FRAME;FRAMESET;HEAD;H1;H2;H3;H4;H5;H6;HR;HTML;I;IFRAME;IMG;" &_
"INPUT;INS;ISINDEX;KBD;LABEL;LAYER;LAGEND;LI;LINK;LISTING;MAP;MARQUEE;" &_
"MENU;META;NOBR;NOFRAMES;NOSCRIPT;OBJECT;OL;OPTION;P;PARAM;PLAINTEXT;" &_
"PRE;Q;S;SAMP;SCRIPT;SELECT;SMALL;SPAN;STRIKE;STRONG;STYLE;SUB;SUP;" &_
"TABLE;TBODY;TD;TEXTAREA;TFOOT;TH;THEAD;TITLE;TR;TT;U;UL;VAR;WBR;XMP;"
Const BLOCKTAGLIST = ";APPLET;EMBED;FRAMESET;HEAD;NOFRAMES;NOSCRIPT;OBJECT;SCRIPT;STYLE;"
Dim nPos1
Dim nPos2
Dim nPos3
Dim strResult
Dim strTagName
Dim bRemove
Dim bSearchForBlock
nPos1 = InStr(strText, "<")
Do While nPos1 > 0
nPos2 = InStr(nPos1 + 1, strText, ">")
If nPos2 > 0 Then
strTagName = Mid(strText, nPos1 + 1, nPos2 - nPos1 - 1)
strTagName = Replace(Replace(strTagName, vbCr, " "), vbLf, " ")
nPos3 = InStr(strTagName, " ")
If nPos3 > 0 Then
strTagName = Left(strTagName, nPos3 - 1)
End If
If Left(strTagName, 1) = "/" Then
strTagName = Mid(strTagName, 2)
bSearchForBlock = False
Else
bSearchForBlock = True
End If
If InStr(1, TAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
bRemove = True
If bSearchForBlock Then
If InStr(1, BLOCKTAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
nPos2 = Len(strText)
nPos3 = InStr(nPos1 + 1, strText, "</" & strTagName, vbTextCompare)
If nPos3 > 0 Then
nPos3 = InStr(nPos3 + 1, strText, ">")
End If
If nPos3 > 0 Then
nPos2 = nPos3
End If
End If
End If
Else
bRemove = False
End If
If bRemove Then
strResult = strResult & Left(strText, nPos1 - 1)
strText = Mid(strText, nPos2 + 1)
Else
strResult = strResult & Left(strText, nPos1)
strText = Mid(strText, nPos1 + 1)
End If
Else
strResult = strResult & strText
strText = ""
End If
nPos1 = InStr(strText, "<")
Loop
strResult = strResult & strText
RemoveHTML_C = strResult
End Function
%>
復(fù)制代碼 代碼如下:
<%
'******************************
'函數(shù):RemoveHTML_A(strText)
'參數(shù):strText,待處理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除HTML代碼中所有標(biāo)簽
'示例:<%=RemoveHTML_A("<b>歡迎光臨阿里西西</b>")%>
'******************************
Function RemoveHTML_A(strText)
Dim nPos1
Dim nPos2
nPos1 = InStr(strText, "<")
Do While nPos1>0
nPos2 = InStr(nPos1+1, strText, ">")
If nPos2>0 Then
strText = Left(strText, nPos1 - 1) & Mid(strText, nPos2 + 1)
Else
Exit Do
End If
nPos1 = InStr(strText, "<")
Loop
RemoveHTML_A = strText
End Function
%>
去除HTML代碼中所有標(biāo)簽之二
復(fù)制代碼 代碼如下:
<%
'******************************
'函數(shù):RemoveHTML_B(strText)
'參數(shù):strText,待處理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除HTML代碼中所有標(biāo)簽
'示例:<%=RemoveHTML_B("<b>歡迎光臨阿里西西</b>")%>
'******************************
Function RemoveHTML_B( strText )
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
RemoveHTML_B = RegEx.Replace(strText, "")
End Function
%>
去除HTML代碼中所有標(biāo)簽之三
復(fù)制代碼 代碼如下:
<%
'******************************
'函數(shù):RemoveHTML_C(strText)
'參數(shù):strText,待處理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除HTML代碼中所有標(biāo)簽
'示例:<%=RemoveHTML_C("<b>歡迎光臨阿里西西</b>")%>
'******************************
Function RemoveHTML_C( strText )
Dim TAGLIST
TAGLIST = ";!--;!DOCTYPE;A;ACRONYM;ADDRESS;APPLET;AREA;B;BASE;BASEFONT;" &_
"BGSOUND;BIG;BLOCKQUOTE;BODY;BR;BUTTON;CAPTION;CENTER;CITE;CODE;" &_
"COL;COLGROUP;COMMENT;DD;DEL;DFN;DIR;DIV;DL;DT;EM;EMBED;FIELDSET;" &_
"FONT;FORM;FRAME;FRAMESET;HEAD;H1;H2;H3;H4;H5;H6;HR;HTML;I;IFRAME;IMG;" &_
"INPUT;INS;ISINDEX;KBD;LABEL;LAYER;LAGEND;LI;LINK;LISTING;MAP;MARQUEE;" &_
"MENU;META;NOBR;NOFRAMES;NOSCRIPT;OBJECT;OL;OPTION;P;PARAM;PLAINTEXT;" &_
"PRE;Q;S;SAMP;SCRIPT;SELECT;SMALL;SPAN;STRIKE;STRONG;STYLE;SUB;SUP;" &_
"TABLE;TBODY;TD;TEXTAREA;TFOOT;TH;THEAD;TITLE;TR;TT;U;UL;VAR;WBR;XMP;"
Const BLOCKTAGLIST = ";APPLET;EMBED;FRAMESET;HEAD;NOFRAMES;NOSCRIPT;OBJECT;SCRIPT;STYLE;"
Dim nPos1
Dim nPos2
Dim nPos3
Dim strResult
Dim strTagName
Dim bRemove
Dim bSearchForBlock
nPos1 = InStr(strText, "<")
Do While nPos1 > 0
nPos2 = InStr(nPos1 + 1, strText, ">")
If nPos2 > 0 Then
strTagName = Mid(strText, nPos1 + 1, nPos2 - nPos1 - 1)
strTagName = Replace(Replace(strTagName, vbCr, " "), vbLf, " ")
nPos3 = InStr(strTagName, " ")
If nPos3 > 0 Then
strTagName = Left(strTagName, nPos3 - 1)
End If
If Left(strTagName, 1) = "/" Then
strTagName = Mid(strTagName, 2)
bSearchForBlock = False
Else
bSearchForBlock = True
End If
If InStr(1, TAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
bRemove = True
If bSearchForBlock Then
If InStr(1, BLOCKTAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
nPos2 = Len(strText)
nPos3 = InStr(nPos1 + 1, strText, "</" & strTagName, vbTextCompare)
If nPos3 > 0 Then
nPos3 = InStr(nPos3 + 1, strText, ">")
End If
If nPos3 > 0 Then
nPos2 = nPos3
End If
End If
End If
Else
bRemove = False
End If
If bRemove Then
strResult = strResult & Left(strText, nPos1 - 1)
strText = Mid(strText, nPos2 + 1)
Else
strResult = strResult & Left(strText, nPos1)
strText = Mid(strText, nPos1 + 1)
End If
Else
strResult = strResult & strText
strText = ""
End If
nPos1 = InStr(strText, "<")
Loop
strResult = strResult & strText
RemoveHTML_C = strResult
End Function
%>
相關(guān)文章
asp 實(shí)現(xiàn)當(dāng)有新信息時(shí)播放語(yǔ)音提示的效果
最近做一套程序的時(shí)候,客戶(hù)要求當(dāng)有新信息的時(shí)候播放一段語(yǔ)音來(lái)提示一下,根據(jù)情況,總結(jié)思路如下2009-06-06asp中將有雙引號(hào)標(biāo)題入庫(kù)的方法
asp中將有雙引號(hào)標(biāo)題入庫(kù)的方法,需要的朋友可以參考下2012-10-10ASP + Serv-u 實(shí)現(xiàn)FTP的代碼
ASP + Serv-u 實(shí)現(xiàn)FTP的代碼...2006-10-10ASP也使用ORM,給ASP上所有的SQL注入畫(huà)上句號(hào)
PS:KJ大牛寫(xiě)的文章,昨天跟一朋友聊天的時(shí)候提到了ADO的command查詢(xún),我竟然把這個(gè)東西給忘記了,看來(lái)記性真的是太差了,找到了kj大牛的文章,拜讀一下。2008-12-12實(shí)例學(xué)習(xí)如何在ASP中調(diào)用DLL
實(shí)例學(xué)習(xí)如何在ASP中調(diào)用DLL...2006-12-12