1. 程式人生 > >ASP去除所有html標簽

ASP去除所有html標簽

nor ignorecas con case rec veh 小寫 function att

ASP去除所有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

Function delHtml(strHtml) '做了一個函數名叫delhtml

    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


Function RemoveHtml(byval strContent)
    Dim objReg ,strTmp
    If strContent="" OR ISNull(strContent) Then Exit Function

    Set objReg=new RegExp
    objReg.IgnoreCase =True
    objReg.Global=True
    objReg.Pattern="<(.[^>]*)>"
    strTmp=objReg.Replace(strContent, "|")
    Set objReg=Nothing
    RemoveHtml=strTmp
    strTmp=""
End Function


str="你好fsdgoijut%%$015$%%fefw%#$fw"
chkstartstr = "%%$" '前邊的標示字符串
chkendstr = "$%%" '後邊的標示字符串
startstr = InStr(str,chkstartstr) + len(chkstartstr) '找到開始位置
endstr = InStr(str,chkendstr) '找到結束位置
censtr = Mid(str,startstr,endstr - startstr) '截取字符串

ASP去除所有html標簽