<% '********************************************** 'strLength函数:计算字符串的长度 '中文字符统计为两个单位长 '********************************************** dim WINNT_CHINESE function strLength(str) ONERRORRESUMENEXT dim WINNT_CHINESE WINNT_CHINESE = (len(""论坛"")=2) if WINNT_CHINESE then dim l,t,c dim i l=len(str) t=l for i=1to l c=asc(mid(str,i,1)) if c<0then c=c+65536 if c>255then t=t+1 endif next strLength=t else strLength=len(str) endif if Err.number<>0then Err.clear end function '********************************************************** 'isInteger函数:判断是否为整数(参数数字与字符串都可) '********************************************************** function isInteger(para) onerrorresumenext dim str dim l,i ifisNUll(para) then isInteger=false exitfunction endif str=cstr(para) iftrim(str)=""""then isInteger=false exitfunction endif l=len(str) for i=1to l ifmid(str,i,1)>""9""ormid(str,i,1)<""0""then isInteger=false exitfunction endif next isInteger=true if err.number<>0then err.clear end function '************************************************* 'cutStr函数:截取前面几个字符,后面添加""""号 '没有区分中文字符长度,即一个中文字长度为1 '************************************************* function cutStr(str,strlen) dim l,t,c l=len(str) t=0 if l<>0then for j=1to l c=Abs(Asc(Mid(str,j,1))) if c>255then t=t+2 else t=t+1 endif if t>=strlen then cutStr=HTMLEncode2(left(str,j)&"""") exitfor else cutStr=HTMLEncode2(str) endif next else cutStr="""" endif end function '******************************************************************************************* 'browser函数:判断浏览器类型(参数info使用request.ServerVariables(""HTTP_USER_AGENT"")调用) '******************************************************************************************* function browser(info) ifInstr(info,""MSIE 5.5"")>0then browser=""浏 览 器:Internet Explorer 5.5"" elseifInstr(info,""MSIE 6.0"")>0then browser=""浏 览 器:Internet Explorer 6.0"" elseifInstr(info,""MSIE 5.01"")>0then browser=""浏 览 器:Internet Explorer 5.01"" elseifInstr(info,""MSIE 5.0"")>0then browser=""浏 览 器:Internet Explorer 5.00"" elseifInstr(info,""MSIE 4.0"")>0then browser=""浏 览 器:Internet Explorer 4.01"" else browser=""浏 览 器:未知"" endif end function '************************************************************************************************ 'system函数:判断客户端操作系统类型(参数info使用request.ServerVariables(""HTTP_USER_AGENT"")调用) '************************************************************************************************ function system(info) ifInstr(info,""NT 5.1"")>0then system=system+""操作系统:Windows XP"" elseifInstr(info,""NT 5"")>0then system=system+""操作系统:Windows 2000"" elseifInstr(info,""NT 4"")>0then system=system+""操作系统:Windows NT4"" elseifInstr(info,""98"")>0then system=system+""操作系统:Windows 98"" elseifInstr(info,""95"")>0then system=system+""操作系统:Windows 95"" else system=system+""操作系统:未知"" endif end function '*************************************************************** 'chkemail函数:检验email的有效性(参数strEmailAddr为email地址) '结果:true 或 false '*************************************************************** Function chkemail(strEmailAddr) Dim re if strEmailAddr<>""""then Set re =new RegExp re.pattern =""^[A-Za-z0-9_.-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,4}$"" chkemail=re.Test(strEmailAddr) else chkemail=true endif end function '**************************************************************** 'chkoicq函数:检验oicq的有效性(参数oicq为oicq号) '结果:true 或 false '**************************************************************** Function chkoicq(oicq) Dim re1 if oicq<>""""then Set re1 =new RegExp re1.IgnoreCase =false re1.global =false re1.Pattern =""[0-9]{4,10}$"" chkoicq = re1.Test(oicq) else chkoicq=true endif End Function '**************************************************************************** 'DateToStr函数:把日期转化为字符串系列(参数dtDateTime为日期字符串或日期型) '结果:年月日时分秒 '**************************************************************************** function DateToStr(dtDateTime) DateToStr =year(dtDateTime) & doublenum(Month(dtdateTime)) & doublenum(Day(dtdateTime)) & _ doublenum(Hour(dtdateTime)) & doublenum(Minute(dtdateTime)) & doublenum(Second(dtdateTime)) &"""" end function '**************************************************************************** 'doublenum函数:把单位数转化为两位数,保持日期位数统一(由DateToStr调用) '结果:双位数 '**************************************************************************** function doublenum(fNum) if fNum >9then doublenum =cstr(fNum) else doublenum =""0""&cstr(fNum) endif end function '**************************************************************************** 'StrToDate函数:把参数year,month,day转化为日期(""year-month-day"") '结果:日期 '**************************************************************************** function StrToDate(year,month,day) StrToDate=cstr(year) &""-""&cstr(month) &""-""&cstr(day) end function '************************************************************************************ 'ChkBadWords函数:过滤不良语句(参数BadWords为不良语句定义,fString为要检验的语句) '结果:将不良语句用*号代替输出 '************************************************************************************ function ChkBadWords(BadWords,fString) ifnot(isnull(BadWords) orisnull(fString)) then bwords =split(BadWords, ""|"") for i =0toubound(bwords) fString =Replace(fString, bwords(i), string(len(bwords(i)),""*"")) next ChkBadWords = fString endif end function '*************************************************************************** 'HTMLEncode函数:将HTML语句转为字符型输出(参数fString为HTML语句) ' '*************************************************************************** function HTMLEncode(fString) ifnotisnull(fString) then fString =replace(fString, "">"", "">"") fString =replace(fString, ""<"", ""<"") fString =Replace(fString, CHR(32), "" "") fString =Replace(fString, CHR(34), """"") fString =Replace(fString, CHR(39), ""'"") fString =Replace(fString, CHR(13), """") fString =Replace(fString, CHR(10) &CHR(10), ""</P><P>"") fString =Replace(fString, CHR(10), "" <BR>"") HTMLEncode = fString endif end function '*************************************************************************** 'HTMLEncode函数:将HTML语句转为字符型输出(参数fString为HTML语句) ' '*************************************************************************** function HTMLEncode2(fString) ifnotisnull(fString) then fString =replace(fString, "">"", "">"") fString =replace(fString, ""<"", ""<"") fString =Replace(fString, CHR(32), "" "") fString =Replace(fString, CHR(34), """"") fString =Replace(fString, CHR(39), ""'"") fString =Replace(fString, CHR(13), """") HTMLEncode2 = fString endif end function '******************************************************************** 'HTMLDecode函数:将语句转为HTML输出(参数fString为字符语句) '******************************************************************** function HTMLDecode(fString) ifnotisnull(fString) then fString =replace(fString, "">"", "">"") fString =replace(fString, ""<"", ""<"") fString =Replace(fString, "" "",CHR(32)) fString =Replace(fString, """"", CHR(34)) fString =Replace(fString, ""'"",CHR(39)) fString =Replace(fString, """", CHR(13)) fString =Replace(fString, ""</P><P>"", CHR(10) &CHR(10)) fString =Replace(fString, ""<BR>"", CHR(10)) HTMLDecode = fString endif end function '*********************************************** 'repleatBlank函数:自动生成n个空格 '*********************************************** function repleatBlank(n) n=cint(n) for u=1to n repleatBlank=repleatBlank &"" "" next end function %>