POST,GET 格式化函数

七 12th, 2010
   'Author:miaoqiyuan.cn
   '函数:Query
    '功能:得到GET提交的字符
    '参数:GET表单名        直接取值
    '      GET表单名.trim   取值并去除两边空格
    '      GET表单名.trimbr 取值并去除两边空格,多行模式
    '      GET表单名.tonum  转换为数字
    '      GET表单名.tohtml 转换为HTML编码的字符
    '      GET表单名.todate 转换为时间,日期
    '      GET表单名.nohtml 取出所有HTML标签
    '      GET表单名.safe   过滤掉可能有安全隐患的字符,防止注入
    '      GET表单名.nobr   过滤掉所有换行符,并转换成<br />
    '举例:a = Query("test")              a 为通过get提交的get的值
    '      a = Query("test.trimbr")       a 被去掉两边的空格
    '      a = Query("test.trim.tohtml")  a 去掉两边空格,并转换成html编码后的字符
    '      a = Query("test.tonum")        a 被转换成 数字
    '返回:处理后的GET提交的字符
    public function Query(byval querystr)
      dim q,v,tmp,i
      q = split(querystr,".")
      v = Request(q(0))
      if ubound(q)>0 then
        for i=0 to ubound(q)
          select case q(i)
            case "trim"
              v = trim(v)
            case "trimbr"
              tmp = ""
              for each x in split(v,vbCrlf)
                if trim(x)<>"" then
                  if tmp="" then
                    tmp = trim(x)
                  else
                    tmp = tmp & vbCrlf & trim(x)
                  end if
                end if
              next
              v = tmp
            case "tonum"
              if isnumeric(v) and trim(v)<>"" then v = cLng(v) else v = 0
            case "tohtml"
              v = server.htmlencode(v)
            case "todate"
              if isdate(todate) and trim(todate)<>"" then v = cDate(v) else v = Date()
            case "nohtml"
	          Set objRegExp = New Regexp
	          objRegExp.IgnoreCase = True
	          objRegExp.Global = True
	          objRegExp.Pattern = "(< [a-zA-Z\?].*?>)|(< [\/][a-zA-Z\?].*?>)"
	          v = objRegExp.Replace(v,"")
	          Set objRegExp = Nothing
	        case "safe"
	          v = replace(v," and","")
	          v = replace(v,"'","’")
	        case "nobr"
	          v = replace(v,vbCrlf,"<br />")
          end select
        next
      end if
      Query = v
    end function
'------------------------------------
'  2010-07-18 更新
'------------------------------------
'  修复了变量i感染全局变量i的Bug
标签:
目前还没有任何评论.