您现在的位置: Gufang > 博客 > 学无止境 > 正文
asp 自动去除字符中含有html代码的几个函数

<%
Function Remove_HTML(Str)
Dim ilen1, ilen2
Do While InStr(1, Str, "<", 1) >0
ilen1 = InStr(1, Str, "<", 1)
ilen2 = InStr(1, Str, ">", 1)
Str = Left(Str, ilen1 -1) & Mid(Str, ilen2 + 1)
Loop
Remove_HTML = Str
End Function


Function RemoveHTMLTag(fString)
Dim re
Set re = New RegExp
re.IgnoreCase = True
re.Pattern = "<(.[^>]*)>"
fString = re.Replace(fString, "")
Set re = Nothing
RemoveHTMLTag = fString
End Function

 

Function RemoveHTMLTag(str)
Set re = New RegExp
re.Pattern = "<[^<>]*>"
re.Global = true
RemoveHTMLTag =re.Replace(str,"")
Set re = Nothing
End Function

Function stripHTML(strHTML)
'Strips the HTML tags from strHTML
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>"
'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, "")
'Replace all < and > with < and >
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")
stripHTML = strOutput 'Return the value of strOutput
Set objRegExp = Nothing
End Function

Function formatStr(strText)
  On Error Resume Next
  strText = Trim(strText)
  If strText="" Then
    Exit Function
  End If
  strText = Replace(strText,";","&#59;")    '分号
  strText = Replace(strText,"&nbsp;","")
  strText = Replace(strText,"<","&lt;")           '左<
  strText = Replace(strText,">","&gt;")        '右>
  strText = Replace(strText,"'","&#39;")    '单引号
  strText = Replace(strText,"""","&quot;")    '双引号
  strText = Replace(strText,Chr(9),"")    '空格
  strText = Replace(strText, Chr(10) & Chr(10), "")
  strText = Replace(strText,Chr(10),"")     '回车
  strText = Replace(strText,Chr(13),"")     '回车
  strText = Replace(strText,Chr(32),"")    '空格
  strText = Replace(strText,Chr(34),"&quot;")    '双引号
  strText = Replace(strText,Chr(39),"&#39;")    '单引号
  strText = Replace(strText,"script","&#115cript")    'script
  strText = Replace(strText,"(","&#40;")            '左(
  strText = Replace(strText,")","&#41;")            '右)
  strText = Replace(strText,"--","&#45;&#45;")    'SQL注释符
  FormatStr = strText
End Function

 

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
%>

发表评论(0)
姓名 *
电子邮件
QQ
评论内容 *
验证问题 * 江苏省的省会是哪个城市?请填写正确答案
验证码 * 图片看不清?点击重新得到验证码