09-04
09

用ASP过滤HTML代码

'删除字符串中的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,"")," ","")
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,"")," ","")
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


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: HTML
相关日志:
评论: 0 | 引用: 0 | 查看次数: 425
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭