作业帮 > ASP > 教育资讯

asp源码:HTML 过滤实用函数

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 07:23:42 ASP
asp源码:HTML 过滤实用函数
asp源码:HTML 过滤实用函数ASP
【无忧考网-asp源码:HTML 过滤实用函数】:

可以过滤处理html标记,但也保留一个不处理标记的参数

function strip_tags(strHTML, allowedTags)
 
        dim objRegExp, strOutput
        set objRegExp = new regexp
 
        strOutput = strHTML
        allowedTags = "," & lcase(replace(allowedTags, " ", "")) & ","
 
        objRegExp.IgnoreCase = true
        objRegExp.Global = true
        objRegExp.MultiLine = true
        objRegExp.Pattern = "<(.|\n)+?>"
        set matches = objRegExp.execute(strHTML)
        objRegExp.Pattern = "<(/?)(\w+)[^>]*>"
        for each match in matches
                tagName = objRegExp.Replace(match.value, "$2")
                if instr(allowedTags, "," & lcase(tagName) & ",") = 0 then
                        strOutput = replace(strOutput, match.value, "")
                end if
        next
        strip_tags = strOutput
        set objRegExp = nothing
end function

ASP