zl程序教程

您现在的位置是:首页 >  前端

当前栏目

截字符串去除HTML标记

HTML 字符串 去除 标记
2023-06-13 09:13:40 时间
<%
"**************************************************
"函数名:gotTopic
"作用:截字符串,汉字一个算两个字符,英文算一个字符
"参数:str----原字符串
"strlen----截取长度
"返回值:截取后的字符串
"**************************************************
functiongotTopic(str,strlen)
ifstr=""then
gotTopic=""
exitfunction
endif
diml,t,c,i
str=replace(replace(replace(replace(str,"",""),""",chr(34)),">",">"),"<","<")
str=replace(str,"?","")
l=len(str)
t=0
fori=1tol
c=Abs(Asc(Mid(str,i,1)))
ifc>255then
t=t+2
else
t=t+1
endif
ift>=strlenthen
gotTopic=left(str,i)&"…"
exitfor
else
gotTopic=str
endif
next
gotTopic=replace(replace(replace(replace(gotTopic,"",""),chr(34),"""),">",">"),"<","<")
endfunction
"=========================================================
"函数:RemoveHTML(strHTML)
"功能:去除HTML标记
"参数:strHTML--要去除HTML标记的字符串
"=========================================================
FunctionRemoveHTML(strHTML)
DimobjRegExp,Match,Matches
SetobjRegExp=NewRegexp
objRegExp.IgnoreCase=True
objRegExp.Global=True
"取闭合的<>
objRegExp.Pattern="<.+?>"
"进行匹配
SetMatches=objRegExp.Execute(strHTML)
"遍历匹配集合,并替换掉匹配的项目
ForEachMatchinMatches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
SetobjRegExp=Nothing
setMatches=nothing
EndFunction
%>