asp去除HTML标记的三个实用函数
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[p]<%[/p]
[p]function removehtml_a(strtext)[br] dim npos1[br] dim npos2[br] [br] npos1 = instr(strtext, "<") [br] do while npos1>0 [br] npos2 = instr(npos1+1, strtext, ">") [br] if npos2>0 then [br] strtext = left(strtext, npos1 - 1) & mid(strtext, npos2 + 1) [br] else [br] exit do [br] end if [br] npos1 = instr(strtext, "<") [br] loop [br] [br] removehtml_a = strtext [br]end function[/p] [p]function removehtml_b(strtext)[br]dim regex[/p] [p]set regex = new regexp[/p] [p]regex.pattern = "<[^>]*>"[br]regex.global = true[/p] [p]removehtml_b = regex.replace(strtext, "")[br]end function[/p] [p]function removehtml_c( strtext )[br] dim taglist[br] taglist = ";!--;!doctype;a;acronym;address;applet;area;b;base;basefont;" &_[br] "bgsound;big;blockquote;body;br;button;caption;center;cite;code;" &_[br] "col;colgroup;comment;dd;del;dfn;dir;div;dl;dt;em;embed;fieldset;" &_[br] "font;form;frame;frameset;head;h1;h2;h3;h4;h5;h6;hr;html;i;iframe;img;" &_[br] "input;ins;isindex;kbd;label;layer;lagend;li;link;listing;map;marquee;" &_[br] "menu;meta;nobr;noframes;noscript;object;ol;option;p;param;plaintext;" &_[br] "pre;q;s;samp;script;select;small;span;strike;strong;style;sub;sup;" &_[br] "table;tbody;td;textarea;tfoot;th;thead;title;tr;tt;u;ul;var;wbr;xmp;"[/p] [p] const blocktaglist = ";applet;embed;frameset;head;noframes;noscript;object;script;style;"[br] [br] dim npos1[br] dim npos2[br] dim npos3[br] dim strresult[br] dim strtagname[br] dim bremove[br] dim bsearchforblock[br] [br] npos1 = instr(strtext, "<")[br] do while npos1 > 0[br] npos2 = instr(npos1 + 1, strtext, ">")[br] if npos2 > 0 then[br] strtagname = mid(strtext, npos1 + 1, npos2 - npos1 - 1)[br] strtagname = replace(replace(strtagname, vbcr, " "), vblf, " ")[/p] [p] npos3 = instr(strtagname, " ")[br] if npos3 > 0 then[br] strtagname = left(strtagname, npos3 - 1)[br] end if[br] [br] if left(strtagname, 1) = "/" then[br] strtagname = mid(strtagname, 2)[br] bsearchforblock = false[br] else[br] bsearchforblock = true[br] end if[br] [br] if instr(1, taglist, ";" & strtagname & ";", vbtextcompare) > 0 then[br] bremove = true[br] if bsearchforblock then[br] if instr(1, blocktaglist, ";" & strtagname & ";", vbtextcompare) > 0 then[br] npos2 = len(strtext)[br] npos3 = instr(npos1 + 1, strtext, "" & strtagname, vbtextcompare)[br] if npos3 > 0 then[br] npos3 = instr(npos3 + 1, strtext, ">")[br] end if[br] [br] if npos3 > 0 then[br] npos2 = npos3[br] end if[br] end if[br] end if[br] else[br] bremove = false[br] end if[br] [br] if bremove then[br] strresult = strresult & left(strtext, npos1 - 1)[br] strtext = mid(strtext, npos2 + 1)[br] else[br] strresult = strresult & left(strtext, npos1)[br] strtext = mid(strtext, npos1 + 1)[br] end if[br] else[br] strresult = strresult & strtext[br] strtext = ""[br] end if[br] [br] npos1 = instr(strtext, "<")[br] loop[br] strresult = strresult & strtext[br] [br] removehtml_c = strresult[br]end function[/p] [p]%>[/p] 该文章在 2010/7/3 14:30:56 编辑过 |
关键字查询
相关文章
正在查询... |