by 清泉
5. 十一月 2008 10:34
使用ewebeditor编辑器里面导入word的时候老是在代码里面加入<style></style>,如果使用普通的HTML过滤正则将无法过滤此内容.再在过滤HTML函数前面加上此函数进行过滤,便可完全过滤HTML代码了.
'此函数用于过滤<style></style>之间的代码
Function LoseStyleTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "(<style)+[^<>]*>[^\0]*(<\/style>)+"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseStyleTag = ClsTempLoseStr
Set regEx = Nothing
End Function
'Asp完全过滤Html代码
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取闭合的<>
objRegExp.Pattern = "<.+?>"
'进行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍历匹配集合,并替换掉匹配的项目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function