When we write HTML code, we sometimes need to remove all tags. It is troublesome to delete tags one by one. So is there any quick and convenient way? Let's take a look at how to remove all tags in HTML code.
Remove all tags in HTML code
The code copy is as follows:<%
'*********************************
'Function: RemoveHTML_A(strText)
'Arguments: strText, string to be processed
'Author: Alixi
'Date: 2007/7/12
'Description: Remove all tags in HTML code
'Example: <%=RemoveHTML_A("<b>Welcome to Alixixi</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
%>
Remove all tags in HTML code
The code copy is as follows:<%
'*********************************
'Function: RemoveHTML_B(strText)
'Arguments: strText, string to be processed
'Author: Alixi
'Date: 2007/7/12
'Description: Remove all tags in HTML code
'Example: <%=RemoveHTML_B("<b>Welcome to Alixixi</b>")%>
'*********************************
Function RemoveHTML_B( strText )
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
RemoveHTML_B = RegEx.Replace(strText, "")
End Function
%>
Remove all tags in HTML code
The code copy is as follows:<%
'*********************************
'Function: RemoveHTML_C(strText)
'Arguments: strText, string to be processed
'Author: Alixi
'Date: 2007/7/12
'Description: Remove all tags in HTML code
'Example: <%=RemoveHTML_C("<b>Welcome to Alixixi</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
%>
This is all about removing all tags in HTML code. I believe everyone has a certain understanding. If you want to know more technical information, please continue to pay attention to the wrong new technology channel!