收藏 分销(赏)

ASP常用函数库.pdf

上传人:曲**** 文档编号:2046367 上传时间:2024-05-14 格式:PDF 页数:84 大小:874.83KB 下载积分:14 金币
下载 相关 举报
ASP常用函数库.pdf_第1页
第1页 / 共84页
ASP常用函数库.pdf_第2页
第2页 / 共84页


点击查看更多>>
资源描述
ASP常用函数库L函数 array()功能:创建一个数组变量格式:array(list)参数:list为数组变量中的每个数值列,中间用逗号间隔例子:结果:i被赋予为数组2.函数 Cint()功能:将一表达式/其它类型的变量转换成整数类型(int)格式:Cint(expression)参数:expression是任何有效的表达式/其它类型的变量例子:结果:236函数Cint()将字符234转换成整数234.如果表达式为空,或者无效 此返回值为0;3.函数:Creatobject()功能:创建及返回一个ActiveX对象格式:Creatobject(obname)参数:obname是对象的名称例子:结果:4,函数 Cstr()功能:将一表达式/其它类型的变量转换成字符类型(string)格式:Cstr(expression)参数:expression是任何有效的表达式/其它类型的变量例子:结果:函数Cstr()将整数5转换成字符5.5.函数 Date()功能:返回当前系统(server端)的日期格式:Date。参数:无例子:结果:05/10/006.函数 Dateadd()功能:计算某个指定的时间和:dateadd(timeinterval,number,date)参数:timeinterval是时间单位(月7日.);number是时间间隔值,date是时间始点.例子:结果:11/4/993:34:45 PM其中m=month;d=day;如果是currentDate格式,则,h=hour;s=second;7.函数 Datediff()功能:计算某量个指定的时间差:datediff(timeinterval,datel,date2,firstdayofweek,firstdayofyear)参数:timeinterval是时间单位;datel,date2是有效的日期表达,firstdayofweek,firstdayofyear 是任意选项.例子:结果:There are 150 days to millenium from 8/4/99.8.函数 day()功能:返回一个整数值,对应于某月的某日格式:day(date)参数:date是一个有效的日期表达式;例子:结果:49函数 formatcurrency()功能:转换成货币格式格 式:formatcurrency(expression,digit,leadingdigit,paren,groupdigit)参数:expression是有效的数字表达式;digit表示小数点后的位数;leadingdigit,paren,groupdigit 是任意选项.例子:结果:$34.3510.函数 Formatdatetime()功能:格式化日期表达式/变量1:formatdatetime(date,nameformat)参数:date为有效的日期表达式/变量;nameformat是指定的日期格式 常量名称.例子:结果:Wednesday,August 04,19991L函数 formatnumberO功能:格式化数字表达式/变量格式:formatnumbe(expression,digit,leadingdigit,paren,groupdigit)参数:express为有效的数字表达式,digit表示小数点后的位 数;leadingdigit,paren,groupdigit 是任意选项例子:结果:23.22212.函数 formatpercent()功能:格式化百分数表达式/变量格式:formatnumber(expression,digit Jeading 7paren,groupdigit)参数:expression是有效的数字表达式,digit表示小数点后的位数;leadingdigit,paren,groupdigit 是任意选项例子:结果:45.23313.函数:hour。功能:返回一个数值,对应于的指定时间.格式:hour(time)参数:time对应于的指定时间.例子:结果:16(24小时制)14.函数 instr()功能:返回一个数值,对应于某字符(串)在另一字符串中的位置.:instr(start,strtobesearched,strsearchfor,compare)参数:start(任选)是从第start位寻找,strtobesearched是被搜索的字符 串,strsearchfor是被寻找的目标.compare是任意选项例子:结果9(字符匕“在strtext字符串的第九位)15.函数 instrrev()功能:返回一个数值,对应于某字符(串)在另一字符串中的位置(从后面 起开始寻找).格式:instrrev(starL strtobesearched,strsearchfor,compare)参数:参考instr(),例子:结果:13,字串号是strtext的第13个字符(从后面起开始寻找)16.函数 int()功能:数字取整格式:int(number)参数:number是任何有效的数字表达式/其它类型的变量例子:结果:322(如果用Cint()则结果是323)17.函数 isarray()功能:返回一个布尔值,判断变量是否为数组.格式:isarray(name)参数:name是变量名称例子:结果:false18.函数 isdate()功能:返回一个布尔值,判断变量是否为日期变量.格式:isdate(expression)参数:expression是任意的变量.例子:结果:true19.函数 isempty()功能:返回一个布尔值,判断变量是否为空.格式:isempty(expression)参数:expression是任意的变量.例子:结果:true20.函数 isnull()功能:返回一个布尔值,判断变量是否包含非法的数据.格式:isnull(expression)参数:expression是任意的变量.例子:结果:false21.函数 lsnumeric()功能:返回一个布尔值,判断变量是否为数字变量,或者是可以转换成数字的其它变量.格式:isnumeric(expression)参数:expression是任意的变量.例子:结果:true.22.函数 lsobject()功能:返回一个布尔值,判断变量是否为对象的变量,格式:isobject(expression)参数:expression是任意的变量.例子:结果:true23.函数:Lbound()功能:返回一个数组的下界.:Lbound(arrayname,dimension)参数:arrayname是数组变量,dimension是任意项例子:结果:o24.函数 Lcase()功能:将一字符类型变量的字符全部变换小写字符.格式:Lcase(string)参数:string是字串变量例子:结果:this is lease!25.函数 left()功能:截取一个字符串的前部分;格式:left(stringjength)参数:string字符串,length截取的长度.例子:结果:this i26.函数 len()功能:返回字符串长度或者变量的字节长度格式:len(string|varname)参数:string字符串;varname任意的变量名称例子:结果:1527.函数 ltrim()功能:去掉字符串前的空格.格式:ltrim(string)参数:string字数例子:结果:Today29.函数 minute()功能:返回一数值,表示分钟格式:minute(time)参数:time是时间变量例子:结果:2330.函数 month()功能:返回一数值,表示月份格式:month(time)参数:time是日期变量例子:结果:931.函数 monthname()功能:返回月份的字符串(名称).格式:Monthname(date,abb)参数:date是日期变量,abb=true时则月份的缩写,例子:结果:April32.函数 Now()功能:返回系统的当前时间和日期.格式:now()参数:无例子:结果:05/10/00 8:45:32 pm33.函数:replace。功能:在字串中查找,替代指定的字串.:replace(strtobesearched,strsearchfor,strreplacewith,start,count,compare)参数:strtobesearched 是字串;strsearchfor是被查找的子字$;strreplacewith是用来替代的子字串.staiXcount,compare是任意选项.例子:结果:this is an orange.34.函数 right()功能:截取一个字符串的后部分格式:right(stringjength)参数:string字符串,length截取的长度.例子:结果:st!35.函数 rnd()功能:返回一个随机数值格式:rnd(numberj参数:number是任意数值.例子:结果:0/1数值之一,无randomizeO,则不能产生随机数.36.函数 round()功能:完整数值格式:round(expression,numright)参数:expression数字表达式;numright任意选项.例子:结果:1237.函数 rtrim()功能:去掉字符串后的空格.格式:rtrim(string)参数:string是字串例子:结果:this is a test!38.函数 second()功能:返回一个整数值.格式:second(time)参数:time是一个有效的时间表达式;例子:结果:3039.函数 strReverse()功能:返回与原字串排列逆向的字串.格式:strreverse(string)参数:string是字串40.重新设定图片大小,返回百分比 function resizelmg(ox,oy,nx,ny)resizeimg=1If ox=nx And oy nx then x 不行y=nx*oy/ox resizeimg=y/oyelseresizelmg=x/oxend ifresizelmg=formatNumber(resizelmg,4)end function4L上传时生成自动口录(以2005_6类似的名称)Function makeMonthDir(vitualRoot,virtual)Dim dirName,dirNameV,fsodirNameV=vitualRoot&Year(Now()&Month(Now()dirName=server.MapPath(dirNameV)response.write DirName&Set fso=server.CreateObjectCScripting.FileSystemObject)if not fso.FolderExists(dirName)thenfso.CreateFolder(dirName)end ifset fso=NothingIf virtual ThenmakeMonthDir=dirNameV&ElsemakeMonthDir=dirName&End ifEnd Function42.删除指定的文件,必须传入虚拟路径Sub DoDelFile(sPathFile)On Error Resume NextDim oFSOSet oFSO=Server.CreateObjectCScripting.FileSystemObject)response.write&Server.MapPath(sPathFile)oFSO.DeleteFile(Server.MapPath(sPathFile)Set oFSO=NothingEnd Sub43.格式化时间(显示)参数:n_Flagl:”yyyy-mm-dd hh:mm:ss2:”yyyy-mm-dcT3:”hh:mm:ss”4:yyyy 年 mm 月 dd 日,5:,yyyymmdd6:MM/DDFunction Format_Time(s_Time,n_Flag)Dim y,m,d,h,mi,sFormat_Time=If lsDate(s_Time)=False Then Exit Function y=cstr(year(s_Time)m=cstr(month(s_Time)If len(m)=1 Then m=0&md=cstr(day(s_Time)If len(d)=lThend=,0&dh=cstr(hour(s_Time)lflen(h)=lThenh=,O&hmi=cstr(minute(s_Time)If len(mi)=1 Then mi=0&mis=cstr(second(s_Time)If len(s)=1 Then s=0&sSelect Case n_FlagCase 1yyyy-mm-dd hh:mm:ssFormat_Time=y&m&d&h&mi&sCase 2yyyy-mm-ddFormat_Time=y&m&dCase 3,hh:mm:ssFormat_Time=h&mi&sCase 4yyyy年mm月dd日Format_Time=y&”年“&m&”月“&d&”日Case 5yyyymmddFormat_Time=y&m&dCase 6mm/ddFormat_Time=m&dcase 7Format_Time=m&d&right(y,2)End SelectEnd Function44.把字符串进行HTML解码,替换server.htmlencode去除Html格式,用于显示输出Function outHTML(str)Dim sTempsTemp=stroutHTML=n,If IsNull(sTemp)=True ThenExit FunctionEnd IfsTemp=Replace(sTemp,&)sTemp=Replace(sTemp,)sTemp=Replace(sTemp,Chr(34),JsTemp=Replace(sTemp,Chr(lO),)outHTML=sTempEnd Function45.去除Html格式,用于从数据库中取出值填入输入框时注意:valued?”这边一定要用双引号Function inHTML(str)Dim sTemp sTemp=strinHTML=If IsNull(sTemp)=True ThenExit FunctionEnd IfsTemp=Replace(sTemp,&)sTemp=Replace(sTemp,)sTemp=Replace(sTemp,Chr(34),JinHTML=sTempEnd Function46.检测上页是否从本站提交返回:True,FalseFunction lsSelfRefer()Dim sHttp_Referer,sServer_NamesHttp_Referer=CStr(Request.ServerVariables(,HTTP_REFERER)sServer_Name=CStr(Request.ServerVariables(,SERVER_NAME)If Mid(sHttp_Referer,8,Len(sServer_Name)=sServer_Name ThenIsSelfRefer=True日seIsSelfRefer=FalseEnd IfEnd Function47得到安全字符串,在查询中使用Function Get_SafeStr(str)Get_SafeStr=Replace(Replace(Replace(Trim(str),Chr(34),Illi jEnd Function48.取实际字符长度Function Get_TrueLen(str)Dim I,t,c,iI=Len(str)t=IFor i=1 To Ic=Asc(Mid(str,i,1)If c 255 Then t=t+1NextGet TrueLen=tEnd Function49.判断是否安全字符串,在注册登录等特殊字段中使用Function IsSafeStr(str)Dim s_BadStr,n,is_BadStr=&?%,;:()!#$A*|+-=&Chr(34)&Chr(9)&Chr(32)n=Len(s_BadStr)IsSafeStr=TrueFor i=1 To nIf lnstr(str,Mid(s_BadStr,i,1)0 ThenIsSafeStr=FalseExit FunctionEnd IfNextEnd Function50.,显示解释函数,返回根据参数允许显示的格式字符串,具体调用方法可从后台管理获得输入参数:s_Content:要转换的数据字符串s_Filters:要过滤掉的格式集,用逗号分隔多个Function jimmycode(s_Content,sFilters)Dim a_Filter,i,s_Result,s_Filtersjimmycode=s_ContentIf lsNull(s_Content)Then Exit FunctionIf s Content=Then Exit Functions_Content=Replace(s_Content,Chr(lO),)s_Result=s_Contents_Filters=sFilters,设置默认过滤If sFilters=Then s_Filters=script,objecta_Filter=Split(s_Filters,For i=0 To UBound(a_Filter)s_Result=jimmycodeFilter(s_Result,a_Filter(i)Nextjimmycode=s_ResultEnd Function51.初始化下拉框,s FieldName:返回的下拉框名a_Name:定值名数组a_Value:定值值数组v_lnitValue:初始值s_Sql:从数据库中取值时,select name,value from tables_AIIName:空值的名称,如:“全部J所有,J默认“Function lnitSelect(s_FieldName,a_Name,a_Value,v_lnitValue,s_Sql,s_AIIName,s_onchange)Dim iInitSelect=select name=&s_FieldName&size=l onChange=&s_onchange&If s_AIIName ThenInitSelect=InitSelect&s_AIIName&End IfIf s_Sql Then ors.Open s_Sql,oConn,0,1Do While Not ors.EofInitSelect=InitSelect&outHTML(oRs(0)&ors.MoveNextLoopors.CloseElseFor i=0 To UBound(a_Name)InitSelect=InitSelect&outHTML(a_Name(i)&NextEnd IfInitSelect=InitSelect&End Function%52.=/单个过滤/输入参数:/s_Content:要转换的数据字符串/s_Filter:要过滤掉的单个格式 function jimmycodeFilter(html,filter)switch(filter.tollpperCase()case SCRIPT:/去除所有客户端脚本javascipt,vbscript,jscript,js,vbs,event,.html=eWebEditor_execRE(,*,html);html=eWebEditor_execRE(javascript|jscript|vbscript|vbs):,$1:,html);html=eWebEditor_execRE(on(mouse|exit|error|click|key),on$l,html);html=eWebEditor_execRE(&#,html);break;case TABLE:/去除表格html=eWebEditor_execRE(,*,html);html=eWebEditor_execRE(*,html);html=eWebEditor_execRE(*,html);html=eWebEditor_execRE(,*,html);break;case CLASS:/去除样式类 class二”html=eWebEditor_execRE(+)class=A|A*(A*),$1$2,html);break;case STYLE:/去除样式 style/,html=eWebEditor_execRE(+)style=p*,(八习*),$1$2,html);break;case XML:/去除 XMLhtml=eWebEditor_execRE(,*,html);break;case NAMESPACE:/去除命名空间html=eWebEditor_execRE(*,html);break;case FONT:/去除字体vfonthtml=eWebEditor_execRE(*,html);break;case P:/去除字体html=eWebEditor_execRE(,*,html);break;case IMG:/去除图片html=eWebEditor_execRE(,*,html);break;case MARQUEE:/去除字幕html=eWebEditor_execRE(,*,html);break;case OBJECT:/去除对象 html=eWebEditor_execRE(,*,html);html=eWebEditor_execRE(,*,html);html=eWebEditor_execRE(,*,html);break;case HTML:html=eWebEditor_execRE(,*,html);break;default:return html;53./=/执行正则表达式替换/=function eWebEditor_execRE(re,rp,content)oreg=new RegExp(re,ig);r=content.replace(oReg,rp);return r;54.用途:获取远程的网页内容示除Uresponse.write getHTTPPage(http:/)response.write getHTTPPage(http:/)function getHTTPPage(url)on error resume nextdim httpset http=Server.createobject(,Microsoft.XMLHTTP)Http.open GET,url,falseHttp.send()if Http.readystate4 thenexit functionend ifgetHTTPPage=bytes2BSTR(Http.responseBody)set http=nothingif err.numberoO then err.Clearend functionFunction bytes2BSTR(vln)dim strReturndim i,ThisCharCode,NextCharCodestrReturn=For i=1 To LenB(vln)ThisCharCode=AscB(MidB(vln,i,l)If ThisCharCode&H80 ThenstrReturn=strReturn&Chr(ThisCharCode)ElseNextCharCode=AscB(MidB(vln,i+l,l)strReturn=strReturn&Chr(CLng(ThisCharCode)Clnt(NextCharCode)&H100+i=i+1End IfNextbytes2BSTR=strReturnEnd Function.55用途:检查str是否为空Function checkNull(str)checkNull=Falseif trim(str)=,or isnull(str)thencheckNull=Trueend ifend Function56*,函数名:strLength作用:求字符串长度。汉字算两个字符,英文算一个字符。修 数:str-要求长度的字符串返回值:字符串长度response.write strength(“中国“)function strLength(str)ON ERROR RESUME NEXTdim WINNT_CHINESEWINNT_CHINESE=(len(“中国”)=2)if WINNT_CHINESEthendim l,t,cdim il=len(str)t=lfor i=l to Ic=asc(mid(str,i,l)if c255 thent=t+lend ifnextstrLength=telsestrLength=len(str)end ifif err.numberoO then err.clearend function57*函数名:isHTTP作 用:检查字符串是否以HTTP开头或以“/”开头,参数:str,注str不能为NULL值编写:杨俊明response.write isHTTP(http:/)Function isHTTP(MyString)if isnull(MyString)then isHTTP=falseif mid(lcase(trim(MyString),1,7)=http:/or left(MyString,l)=,7 thenisHTTP=trueelseisHTTP=Falseend ifend function58作用:检查组件是否已经安装参数:strClassString 组件名返回值:True-已经安装False-没有安装示例:response.write lsObjlnstalled(Adodb.recordset)编写:网上搜索Function IsObjlnstalled(strClassString)On Error Resume NextIsObjlnstalled=FalseErr=ODim xTestObjSet xTestObj=Server.CreateObject(strClassString)If 0=Err Then IsObjlnstalled=TrueSet xTestObj=NothingErr=0End Function59=网上搜集=过程名:ShowArticleContent 作 用:显示文章具体的内容,可以分页显示参数:ShowContentByPage,s_content,MaxPerPage_Content调用示例:ShowContentByPagedyes是否使用文章分页(为No,则表示关闭)s_content=一 l二 2 三 3 四v/font4 五六七八九十”要分页显示的字符串MaxPerPageontent=15 每页显示的字数(注意,html源代码也计算 在内)callShowArticleContent(ShowContentByPage,s_content,MaxPerPage_Content)call$卜0巾(2住03讨0位(“丫051”12345678914)有问题subShowArticleContent(ShowContentByPage,s_content,MaxPerPage_Conte nt)on error resume next dim ArticlelD,strContent,CurrentPage,GoUrl,GoParmdim ContentLen,MaxPerPage,pages,iJngBounddim BeginPoint,EndPointGollrl=request.ServerVariablesCurl)GoParm=trim(request.ServerVariables(,query_string)if isNull(GoPram)then GoParm=,if instr(GoParm,ArticlePage,)0 then GoParmleft(GoParm,instr(GoParm,ArticlePage,)-l)if right(GoParm,l)=&”then GoParm=left(GoParm,len(GoParm)-l)if GoParm,thenGoUrl=GoUrl&?&GoParm&elseGoUrl=GoUrl&?end ifShowContentByPage=ucase(ShowContentByPage)ArticlelD=cint(s_id)strContent=s_contentContentLen=len(strContent)CurrentPage=trim(request(,ArticlePage,)if ShowContentByPage=,NO or ContentLen=MaxPerPage_Content thenresponse.write strContentif ShowContentByPage=,YES thenresponse.write end ifelseif CurrentPage=,thenCurrentPage=lelseCurrentPage=Cint(CurrentPage)end ifpages=ContentLenMaxPerPage_Content if MaxPerPage_Content*pagesContentLen thenpages=pages+lend iflngBound=MaxPerPage_Content 最大误差范围if CurrentPagepages then CurrentPage=pagesdim IngTempdimlngTempl,lngTempl_l,lngTempl_2,lngTempl_l_l,lngTempl_l_2,lngTempl_l_3,lngTempl_2_l,lngTempl_2_2,lngTempl_2_3dimlngTemp2,lngTemp2_l,lngTemp2_2,lngTemp2_l_l,lngTemp2_l_2,lngTe mp2_2_l,lngTe mp2_2_2dimlngTemp3,lngTemp3_l,lngTemp3_2,lngTemp3_l_l,lngTemp3_l_2,lngT e m p3_2_l,lngTem p3_2_2dimlngTemp4,lngTemp4_l,lngTemp4_2,lngTemp4_l_l,lngTemp4_l_2,lngTe m p4_2_l,lngTem p4_2_2dim lngTemp5,lngTemp5_l,lngTemp5_2dim lngTemp6,lngTemp6_l,lngTemp6_2if CurrentPage=l thenBeginPoint=lelseBeginPoint=MaxPerPage_Content*(CurrentPage-l)+llngTempl_l_l=instr(BeginPoint,strContent,l)lngTempl_l_2=instr(BeginPoint,strContent,l)lngTempl_l_3=instr(BeginPoint,strContent,l)if lngTempl_l_l0 thenlngTempl_l=lngTempl_l_lelseif lngTempl_l_20 thenlngTempl_l=lngTempl_l_2elseif lngTempl_l_30 thenlngTempl_l=lngTempl_l_3elselngTempl_l=Oend iflngTempl_2_l=instr(BeginPoint/strContent/,table/l)lngTempl_2_2=instr(BeginPoint,strContent,TABLE,1)lngTempl_2_3=instr(BeginPoint,strContent,0 thenlngTempl_2=lngTempl_2_lelseif lngTempl_2_20 then lngTempl_2=lngTempl_2_2elseif lngTempl_2_30 then lngTempl_2=lngTempl_2_3elselngTempl_2=0end ifif lngTempl_l=O and lngTempl_2=0 thenlngTempl=BeginPointelseif lngTempl_llngTempl_2 thenlngtempl=lngTempl_2elselngTempl=lngTempl_l+8end ifend iflngTemp2_l_l=instr(BeginPoint,strContent,l)lngTemp2_l_2=instr(BeginPoint,strContent,1)if lngTemp2_l_l0 thenlngTemp2_l=lngTemp2_l_lelseif lngTemp2_l_20 thenlngTemp2_l=lngTemp2_l_2elselngTemp2_l=0end iflngTemp2_2_l=instr(BeginPoint,strContent,0 thenIngTe mp2_2=lngT e mp2_2_lelseif lngTemp2_2_20 thenIngTe mp2_2=lngT e mp2_2_2elselngTemp2_2=0end if if lngTemp2_l=0 and lngTemp2_2=0 thenlntTemp2=BeginPoint elseif lngTemp2_llngTemp2_2 thenlngtemp2=lngTemp2_2elselngTemp2=lngTemp2_l+4end ifend iflngTemp3_l_l=instr(BeginPoint,strContent,l)lngTemp3_l_2=instr(BeginPoint,strContent,l)if lngTemp3_l_l0 thenlngTemp3_l=lngTemp3_l_lelseif lngTemp3_l_20 thenlngTemp3_l=lngTemp3_l_2elselngTemp3_l=0 end iflngTemp3_2_l=instr(BeginPoint,strContent,ur,!)lngTemp3_2_2=instr(BeginPoint,strContent,if lngTemp3_2_l0 thenlngTemp3_2=lngTemp3_2_lelseif lngTemp3_2_20 thenIngTem p3_2=lngT e m p3_2_2elselngTemp3_2=0end ifif lngTemp3_l=0 and lngTemp3_2=0 thenlngTemp3=BeginPointelseif lngTemp3_llngTemp3_2 thenlngtemp3=lngTemp3_2elselngTemp3=lngTemp3_l+5end ifend ifif lngTempllngTemp2 thenlngTemp=lngTemp2elseIngTemp=IngTemplend ifif lngTempBeginPoint and lngTemp=BeginPoint+lngBound then BeginPoint=lngTempelselngTemp4_l_l=instr(Be
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服