尹学洪,多媒体光盘,年鉴光盘,地方志光盘,志书光盘,光盘导航,志鉴光盘制作

用ASP过滤HTML代码

作者:江苏锐德 2010-8-21 21:14:26 人气:

'删除字符串中的HTML代码

function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(\<.[^\<]*\>)"
str=re.replace(str," ")
re.Pattern="(\<\/[^\<]*\>)"
str=re.replace(str," ")
nohtml=str
set re=nothing
end function

=========================================

'删除字符串中的HTML代码

Function DelHtml(Str1)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "(<[^>]*?>)"
regEx.Global = True
regEx.IgnoreCase = True
DelHtml = replace(regEx.Replace(""&str1,""),"&nbsp;","")
End Function

=========================================

'删除字符串中的HTML代码

Function DelHtml(ContentStr)
Dim TempLoseStr, regEx
TempLoseStr = CStr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<\/*[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
TempLoseStr = replace(regEx.Replace(TempLoseStr,""),"&nbsp;","")
DelHtml = TempLoseStr
End Function

=========================================

'删除字符串中的HTML代码

Public Function LoseHtml(ContentStr)
On Error Resume Next
Dim TempLoseStr, regEx
If ContentStr="" Or ContentStr=Null Then Exit Function
TempLoseStr = CStr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<\/*[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
TempLoseStr = regEx.Replace(TempLoseStr, "")
LoseHtml = TempLoseStr
End Function


补充:
JS去掉HTML标记的正则

function delHtmlTag(str){
return str.replace(/<\/?.+?>/g,"");//去掉所有的html标记
}
//这个可能IE5会错,那用这个,梅花的:
function delHtmlTag(str){
return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}


======================================

过滤HTML代码和javascript代码以及CSS代码

public Function RemoveHTML(strHTML)
ON ERROR RESUME NEXT
Dim objRegExp, strOutput
strHTML = replace(strHTML," ","")
strHTML = replace(strHTML,chr(13),"")
strHTML = replace(strHTML,chr(10),"")
strHTML = replace(strHTML,chr(32),"")

Set objRegExp = New Regexp
objRegExp.IgnoreCase = True '忽略大小写
objRegExp.Global = True '设置为全文搜索
objRegExp.Pattern = "<script.+?>[\s\S]+?<\/script>"
strOutput = objRegExp.Replace(strHTML, "")
objRegExp.Pattern = "<style.+?>[\s\S]+?<\/style>"
strOutput = objRegExp.Replace(strOutput, "")
objRegExp.Pattern = "<.+?>" '取闭合的<>
strOutput = objRegExp.Replace(strOutput, "")

strOutput = Replace(strOutput, "<", "〈")
strOutput = Replace(strOutput, ">", "〉")
RemoveHTML = strOutput
Set objRegExp = Nothing
End Function
上一篇:DELL VOSTRO 220S 如何重装系统?
下一篇:如何让ZB首页只显示指定分类的文章?
共有:条评论信息评论信息
发表评论
姓 名: 验证码: