09-04
09
用ASP过滤HTML代码
作者:Java伴侣 日期:2009-04-09
'删除字符串中的HTML代码
=========================================
'删除字符串中的HTML代码
=========================================
'删除字符串中的HTML代码
=========================================
'删除字符串中的HTML代码
补充:
JS去掉HTML标记的正则
//这个可能IE5会错,那用这个,梅花的:
======================================
过滤HTML代码和javascript代码以及CSS代码
复制内容到剪贴板 程序代码
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
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
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
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
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标记
}
return str.replace(/<\/?.+?>/g,"");//去掉所有的html标记
}
//这个可能IE5会错,那用这个,梅花的:
复制内容到剪贴板 程序代码
function delHtmlTag(str){
return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}
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
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
评论: 0 | 引用: 0 | 查看次数: 424
发表评论