去除HTML代码中所有标签的两种方法
程序员文章站
2023-08-24 12:24:25
去除html代码中所有标签复制代码 代码如下:<% '****************************** '函数:removehtml_a(strtext)...
去除html代码中所有标签
<%
'******************************
'函数:removehtml_a(strtext)
'参数:strtext,待处理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除html代码中所有标签
'示例:<%=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代码中所有标签之二
<%
'******************************
'函数:removehtml_b(strtext)
'参数:strtext,待处理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除html代码中所有标签
'示例:<%=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代码中所有标签之三
<%
'******************************
'函数:removehtml_c(strtext)
'参数:strtext,待处理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除html代码中所有标签
'示例:<%=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
%>
复制代码 代码如下:
<%
'******************************
'函数:removehtml_a(strtext)
'参数:strtext,待处理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除html代码中所有标签
'示例:<%=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代码中所有标签之二
复制代码 代码如下:
<%
'******************************
'函数:removehtml_b(strtext)
'参数:strtext,待处理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除html代码中所有标签
'示例:<%=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代码中所有标签之三
复制代码 代码如下:
<%
'******************************
'函数:removehtml_c(strtext)
'参数:strtext,待处理的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:去除html代码中所有标签
'示例:<%=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
%>
上一篇: asp实现取得数组中的最大值的代码