zoukankan      html  css  js  c++  java
  • 运用正则表达式在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

    过滤图片正则表达式

    <img.+?>

    Asp过滤Html代码方法二

    Function delHtml(strHtml)

    Dim objRegExp, strOutput
    Set objRegExp = New Regexp ' 建立正则表达式

    objRegExp.IgnoreCase = True ' 设置是否区分大小写
    objRegExp.Global = True '是匹配所有字符串还是只是第一个
    objRegExp.Pattern = "(<[a-zA-Z].*?>)|(<[/][a-zA-Z].*?>)" ' 设置模式引号中的是正则表达式,用来找出html标签

    strOutput = objRegExp.Replace(strHtml, "") '将html标签去掉
    strOutput = Replace(strOutput, "<", "<") '防止非html标签不显示
    strOutput = Replace(strOutput, ">", ">")
    delHtml = strOutput

    Set objRegExp = Nothing
    End Function

    'srt1是你要去除html代码字符串,可以其它任何地方读取过来。
    str1 = "<meta http-equiv=""refresh"" content=""0;URL=apple/default.htm""><title>正</3>在转到 ... ...</title>"
    '应用函数
    Response.Write(delHtml(str1))

    Asp过滤Html代码方法三

    转化html标签为code代码

    function coder(str)
    dim i
    if isnull(str) then : coder="" : exit function : end if
    for i = 1 to len(str)
    select case mid(str,i,1)
    case "<" : coder = coder &"&lt;"
    case ">" : coder = coder &"&gt;" 
    case "&" : coder = coder &"&amp;"
    case chr(9) : coder = coder &"&nbsp; &nbsp; "
    case chr(13) : coder = coder &"<br>"
    case chr(32) : coder = coder &"&nbsp;"
    case chr(34) : coder = coder &"&quot;"
    case chr(39) : coder = coder &"&#39;"
    case else : coder = coder & mid(str,i,1)
    end select
    next
    end function


    过滤javascript字符

    function movejs(str)
    dim objregexp,str1

    set objregexp=new regexp

    objregexp.ignorecase =true

    objregexp.global=true


    objregexp.pattern="<script.+?</script>"

    a=objregexp.replace(str,"")

    objregexp.pattern="<[^<]+>"

    movejs=objregexp.replace(a,"")
    end function


    过滤html标签只剩<br>

    function filterhtml(byval fstring)
    if isnull(fstring) or trim(fstring)="" then
    filterhtml=""
    exit function
    end if

    fstring = replace(fstring, "<br />", "[br]")
    fstring = replace(fstring, "<br>", "[br]")

    '过滤html标签
    dim re
    set re = new regexp
    re.ignorecase=true
    re.global=true
    re.pattern="<(.+?)>"
    fstring = re.replace(fstring, "")
    set re=nothing

    fstring = replace(fstring, "[br]", "<br />")
    filterhtml = fstring
    end function

  • 相关阅读:
    linux c++ 实现http请求
    pip 换源
    Web API接口
    DRF框架知识总览
    jq+bs插件
    element-ui插件
    axios插件
    前端存储数据汇总
    Vuex插件
    全局配置css和js
  • 原文地址:https://www.cnblogs.com/hellen-li/p/5253314.html
Copyright © 2011-2022 走看看