以下这些函数是我这么多年来的一个总结,有些是在工作中不断总结出来的,有些是通过网络的一些例程收集回来的,希望这些能对大家有帮助,多谢!
'自定义MyFormatDateTime函数的FormatType参数项目Const fdDefaultDateTime=1 '格式为:yyyy-m-d h:m:sConst fdDefaultDate=2 '格式为:yyyy-m-dConst fdDefaultTime=3 '格式为:h:m:sConst fdChineseDate=4 '格式为:yyyy年m月d日Const fdLongDateTime=5 '格式为:yyyy-mm-dd hh:mm:ssConst fdLongDate=6 '格式为:yyyy-mm-dd Const fdLongTime=7 '格式为:hh:mm:ss
'自定义获取QueryString、Form、Cookies、ServerVariables值GetRequestValue函数的mode参数Const gvALL=1 '等于:request("key")Const gvForm=2 '等于:request.form("key")Const gvQuery=3 '等于:request.QueryString("key")Const gvCookies=4 '等于:request.Cookies("key")Const gvIP=5 '等于:Request.ServerVariables("REMOTE_ADDR")Const gvURL=6 '等于:Request.ServerVariables("URL")
'自定义函数CheckInput函数DataType参数Const ciNumber=1Const ciString=2Const ciDateTime=3
'*********************************************************' 目的: 对日期输出进行格式化' ' 输入: data:要输出的数字' FormatType:日期格式' Const fdDefaultDateTime=1 '格式为:yyyy-m-d h:m:s' Const fdDefaultDate=2 '格式为:yyyy-m-d' Const fdDefaultTime=3 '格式为:h:m:s' Const fdChineseDate=4 '格式为:yyyy年m月d日' Const fdLongDateTime=5 '格式为:yyyy-mm-dd hh:mm:ss' Const fdLongDate=6 '格式为:yyyy-mm-dd ' Const fdLongTime=7 '格式为:hh:mm:ss'' 返回值: 格式化后的日期字符串' '*********************************************************Function MyFormatDateTime(data,FormatType) if not(isdate(data)) then data=date select case FormatType case fdDefaultDateTime data=year(data)&"-"&month(data)&"-"&day(data)&" "&hour(data)&":"&minute(data)&":"&second(data) case fdDefaultDate data=year(data)&"-"&month(data)&"-"&day(data) case fdDefaultTime data=hour(data)&":"&minute(data)&":"&second(data) case fdChineseDate data=year(data)&"年"&month(data)&"月"&day(data)&"日" case fdLongDateTime data=year(data)&"-"&MyFormatNumber(month(data),2)&"-"&MyFormatNumber(day(data),2)&" "&MyFormatNumber(hour(data),2)&":"&MyFormatNumber(minute(data),2)&":"&MyFormatNumber(second(data),2) case fdLongDate data=year(data)&"-"&MyFormatNumber(month(data),2)&"-"&MyFormatNumber(day(data),2) case fdLongTime data=MyFormatNumber(hour(data),2)&":"&MyFormatNumber(minute(data),2)&":"&MyFormatNumber(second(data),2) end Select MyFormatDateTime=dataEnd Function
'*********************************************************' 目的: 对数字输出进行格式化' ' 输入: data:要输出的数字' NumLength:要输出的数字长度' 例如:data=1 NumLength=3 返回 001' data=11 NumLength=5 返回 00011'' 返回值: 格式化后的数字字符串' '*********************************************************Function MyFormatNumber(data,NumLength) dim FillLength Filllength=NumLength-len(data) MyFormatNumber=String(Filllength,"0") & dataEnd Function
'*********************************************************' 目的: 对输出字符串进行HTML编码' ' 输入: p_STR:要输出的字符'' 返回值: 替换后的字符串' '*********************************************************Function HTMLEncode(p_STR) if not isnull(p_STR) then p_STR = replace(p_STR, ">", ">") p_STR = replace(p_STR, "<", "<") p_STR = Replace(p_STR, CHR(32), " ") p_STR = Replace(p_STR, CHR(9), " ") p_STR = Replace(p_STR, CHR(34), """) p_STR = Replace(p_STR, CHR(39), "'") p_STR = Replace(p_STR, CHR(13) , "<BR>") HTMLEncode = p_STR End ifEnd Function
'*********************************************************' 目的: 对输出字符串进行UBB替换' ' 输入: p_STR:要输出的字符串'' 返回值: 替换后的字符串' '*********************************************************function UBBCode(p_STR) p_STR = HTMLEncode(p_STR) dim re Set re=new RegExp re.IgnoreCase =true re.Global=True
re.Pattern="(?:/[IMG/])(.[^/[]*)(?:/[//IMG/])" strContent=re.Replace(p_STR,"<div width='100%' align='center'><img width='460' src=""$1"" border=""0""></div>") re.Pattern="(?:/[B/])(.[^/[]*)(?:/[//B/])" strContent=re.Replace(p_STR,"<b>$1</b>") re.Pattern="(?:/[URL=(.[^/[]*)/])(.[^/[]*)(?:/[//URL/])" strContent=re.Replace(p_STR,"<a href=""$1"" target=""_blank"">$2</a>") set re=Nothing UBBCode=p_STRend function
'*********************************************************' 目的: 替代response.write p_Str' ' 输入: p_STR:要输出的字符串'' 返回值: 无' '*********************************************************Function echo(p_STR) response.write p_Strend function
'*********************************************************' 目的: 替代response.write p_Str & "<br>"' response.end' ' 输入: p_STR:要输出的字符串'' 返回值: 无' '*********************************************************Function die(p_STR) echo p_Str response.endend function
'*********************************************************' 目的: 替代response.write p_Str & "<br>"' ' 输入: p_STR:要输出的字符串'' 返回值: 无' '*********************************************************Function echobr(p_STR) echo p_Str & "<br>" & vbCRLFend function
'*********************************************************' 目的: 替代request.cookies("key")=p_STR' ' 输入: key: 输出的关键字' p_STR:要输出的字符串' pExpires:cookies存在时间 '' 返回值: 无' '*********************************************************Function echock(key,p_STR,pExpires) response.cookies(key)=p_STR if not (isnull(pExpires) or pExpires="") then response.cookies(key).Expires=pExpiresEnd Function
'*********************************************************' 目的: 替代Request的取值' ' 输入: key: 取值的关键字' pMode:取值方式' Const gvALL=1 '等于:request("key")' Const gvForm=2 '等于:request.form("key")' Const gvQuery=3 '等于:request.QueryString("key")' Const gvCookies=4 '等于:request.Cookies("key")' Const gvIP=5 '等于:Request.ServerVariables("REMOTE_ADDR")' Const gvURL=6 '等于:Request.ServerVariables("URL")'' 返回值: 返回request后的值' '*********************************************************Function GetRequestValue(key,pMode) dim p_STR Select Case pMode Case gvALL p_STR=request(key) Case gvForm p_STR=request.form(key) Case gvQuery p_STR=request.querystring(key) Case gvCookies p_STR=request.cookies(key) Case gvIP P_STR=Request.ServerVariables("REMOTE_ADDR") Case gvURL p_STR=Request.ServerVariables("URL") End Select GetRequestValue=p_STREnd Function
'*********************************************************' 目的: 对用户提交的数据进行类型检查' ' 输入: exp1: 要检查的数据' DataType:要检查的数据类型。' ciNumber:数字 ' ciString:字符' ciDateTime:日期' DefaultValue:缺省值。' 返回值: 如果数据通过检查则返回原值,字符类型需要替换单引号。' 如果不符合则返回缺省值'*********************************************************Function CheckInput(exp1,DataType,DefaultValue) dim exp2 if isnull(exp1) or exp1="" then exp2=DefaultValue else Select Case DataType case ciString exp2=Replace(exp1,"'","''") case ciNumber if isNumeric(exp1) then exp2=exp1 else exp2=DefaultValue end if case ciDateTime if isdate(exp1) then exp2=exp1 else exp2=DefaultValue end if end select end if CheckInput=exp2End Function
本文来自博客,转载请标明出处:http://blog.csdn.net/tianxiaode/archive/2006/07/15/923268.aspx
