几个常用的函数

'求字符串长度函数
Function GetLength(str)
    Dim i,length
    For i = 1 to Len(str)
        If Asc(Mid(str,i,1))<0 or Asc(Mid(str,i,1))>256 Then
            length = length+2
        Else
            length = length+1
        End If
    Next
    GetLength = length
End Function
'防止外部提交
Function ChkPost()
    Dim URL1,URL2
    ChkPost = False
    URL1 = Cstr(Request.ServerVariables("HTTP_REFERER"))
    URL2 = Cstr(Request.ServerVariables("SERVER_NAME"))
    If Mid(URL1,8,Len(URL2))<>URL2 Then
        ChkPost = False
    Else
        ChkPost = True
    End If
End Function
'过滤HTML字符函数
Function HTMLEncode(fString)
If Not IsNull(fString) And fString <> "" Then
    fString = Replace(fString, ">", "&gt;")
    fString = Replace(fString, "<", "&lt;")
    fString = Replace(fString, Chr(32), "&nbsp;")
    fString = Replace(fString, Chr(9), "&nbsp;&nbsp;")
    fString = Replace(fString, Chr(34), "&quot;")
    fString = Replace(fString, Chr(39), "&#39;")
    fString = Replace(fString, Chr(13), "")
    fString = Replace(fString, Chr(10) & Chr(10), "</P><P>")
    fString = Replace(fString, Chr(10), "<BR>")
    fString = Replace(fString, Chr(255), "&nbsp;")
    HTMLEncode = fString
End If
End Function
'清除HTML标记
Function stripHTML(strHTML)
    Dim objRegExp,strOutput
    Set objRegExp = New Regexp
    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    objRegExp.Pattern = "<.+?>"
    strOutput = objRegExp.Replace(strHTML,"")
    strOutput = Replace(strOutput, "<","&lt;")
    strOutput = Replace(strOutput, ">","&gt;")
    stripHTML = strOutput
    Set objRegExp = Nothing
End Function
'获取用户真实IP函数
Function GetIP()
    GetIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If GetIP = "" Then GetIP = Request.ServerVariables("REMOTE_ADDR")
End Function
'获取完整地址栏地址
Function GetUrl()
    GetUrl="http://"&Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("URL")
    If Request.ServerVariables("QUERY_STRING")<>"" Then GetURL=GetUrl&"?"& Request.ServerVariables("QUERY_STRING")
End Function
'获取本页文件名
Function SelfName()
    SelfName = Mid(Request.ServerVariables("URL"),InstrRev(Request.ServerVariables("URL"),"/")+1)
End Function


本文引用通告地址: http://blog.csdn.net/Mapleleaf123/services/trackbacks/374983.aspx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值