欢迎光临
我们一直在努力

我写ASP时常用到的一些函数-ASP教程,ASP应用

建站超值云服务器,限时71元/月

对于asp语言来说,把某一功能模块写成类,那对于效率来讲,未必是件很提倡的事,但是把这种模块化向小了去说,把一些功能写成函数,那就对于在asp开发的时候,省不少事了,以下是一些我经常用到的函数,有一些是我写的,有的是从网上找的,比如说cfs编码的;网上的cfs编码的函数里面的变量都没声明,所以在我的页面声明了option explicit后就不能正常使用了,很简单,我在function里把变量声明了就可以了。

这儿只是一部分,因为我现在在公司,而我的大部分资料都在家里电脑上,以后再补充了……大家如果有什么好的有和的函数,也欢迎和我交流……

@转换日期为星期几函数@idate为标准日期格式@itype为0时表示英文星期几,否则为中文function showweek(idate,itype)if itype <> 0 then itype = 1 //防止误输出错dim inum,ndayinum = weekday(idate)if itype = 0 then select case inum case 1 nday = "sunday" case 2 nday = "monday" case 3 nday = "tuesday" case 4 nday = "wednesday" case 5 nday = "thursday" case 6 nday = "friday" case 7 nday = "saturday" end selectelse select case inum case 1 nday = "星期天" case 2 nday = "星期一" case 3 nday = "星期二" case 4 nday = "星期三" case 5 nday = "星期四" case 6 nday = "星期五" case 7 nday = "星期六" end selectend if//output showweek = ndayend function//*************************************************************

@分页列表函数@参数说明:totalrecount:记录总数@page:当前页码,pagesize:分页大小,url:页面地址function pagelist(totalrecount,page,pagesize,url)dim startpage,endpage,ipage,totalpage//判断链接文件后参数个数if instr(1,url,"?") = 0 then url = url & "?"else url = url & "&amp;"end if//得到总页数totalpage = totalrecount \ pagesizeif totalrecount mod pagesize <> 0 then totalpage = cint(totalrecount\pagesize+1)startpage = 1endpage = totalpageif page > 10 then startpage = page – 4if totalpage < 10 then endpage = totalpageelse if page =< 10 then endpage = 10 else endpage = page + 4 if endpage > totalpage then endpage = totalpage end ifend if%>共有:<%=totalrecount%>&nbsp;<%=pagesize%>页 <%if page>1 then%><a href="<%=url%>page=1"><font face="webdings">9</font></a>&nbsp;<a href="<%=url%>page=<%=page-1%>"><font face="webdings">7</font></a>&nbsp;<%end if%><%for ipage = startpage to endpageif ipage <> page then%> <a href=""><%=ipage%></a>&nbsp;<%else response.write i&"&nbsp;"end ifnext%><%if (totalpage-page)>4 then%><a href="<%=url%>page=<%=page+1%>"><font face="webdings">8</font></a>&nbsp;<a href="<%=url%>page=<%=totalpage%>"><font face="webdings">:</font></a>&nbsp;<%end if

end function//*************************************************************

//检测组件是否安装函数function isobjinstalled(strclassstring)on error resume next isobjinstalled = false err = 0 dim xtestobj set xtestobj = server.createobject(strclassstring) if 0 = err then isobjinstalled = true set xtestobj = nothing err = 0end function//*************************************************************

function saferequest(paraname,paratype) 防止sql注入攻击代码— 传入参数 —//例: saferequest("username",0)或saferequest("id",1)paraname:参数名称-字符型paratype:参数类型-数字型(1表示参数是数字,0表示参数为字符)

dim paravalue paravalue=request(paraname) if paratype=1 then if not isnumeric(paravalue) then response.write "<script language=javascript>alert(参数" & paraname & "必须为数字型!);</script>" response.write "<script language=javascript>window.history.back();</script>" response.end elseif paravalue < 1 then paravalue = 1 end if else paravalue=replace(paravalue,"","") end if saferequest=paravalueend function//*************************************************************

//html解码函数function htmldecode(fstring) if not isnull(fstring) then fstring = replace(fstring, "&gt;", ">") fstring = replace(fstring, "&lt;", "<") fstring = replace(fstring, " ", chr(32)) &nbsp; fstring = replace(fstring, " ", chr(9)) &nbsp; fstring = replace(fstring, "&quot;", chr(34)) 双引号过滤 fstring = replace(fstring, chr(39), "&#39;") 单引号过滤 fstring = replace(fstring, ,"" chr(13)) fstring = replace(fstring, "</p><p>", chr(10) & chr(10)) fstring = replace(fstring, "<br>", chr(10)) htmldecode = fstring end ifend function//*************************************************************

//html编码函数function htmlencode(fstring) if not isnull(fstring) then fstring = replace(fstring, ">", "&gt;") fstring = replace(fstring, "<", "&lt;") fstring = replace(fstring, chr(32), " ") &nbsp; fstring = replace(fstring, chr(9), " ") &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>") htmlencode = fstring end ifend function//*************************************************************

cfs encode functionfunction cfsencode(codestr)dim codelendim codespacedim newcodedim cecr,cecb,ceccodelen = 30codespace = codelen – len(codestr)if not codespace < 1 then for cecr = 1 to codespace codestr = codestr & chr(21) nextend ifnewcode = 1dim beenfor cecb = 1 to codelen been = codelen + asc(mid(codestr,cecb,1)) * cecb newcode = newcode * beennextcodestr = newcodenewcode = emptyfor cec = 1 to len(codestr) newcode = newcode & cfscode(mid(codestr,cec,3))nextfor cec = 20 to len(newcode) – 18 step 2 cfsencode = cfsencode & mid(newcode,cec,1)nextend function

function cfscode(word)dim ccfor cc = 1 to len(word) cfscode = cfscode & asc(mid(word,cc,1))nextcfscode = hex(cfscode)end function//*************************************************************

//转换中文货币大小写function clmoney(thenumber) dim money,i,string1,string2,length,checkp定义变量 dim one(),onestr()定义数组

string1 = "零壹贰叁肆伍陆柒捌玖" string2 = "万仟佰拾亿仟佰拾万仟佰拾元角分厘毫"

checkp=instr(thenumber,".")判断是否含有小数位 if checkp<>0 then thenumber=replace(thenumber,".","")去除小数位 end if

length=len(thenumber) 取得数据长度 redim one(length-1)重新定义数组大小 redim onestr(length-1)重新定义数组大小

for i=0 to length-1

one(i)=mid(thenumber,i+1,1) 循环取得每一位的数字 one(i)=mid(string1,one(i)+1,1)循环取得数字对应的大写

if checkp=0 then 不含有小数的数据其数字对应的单位 onestr(i)=mid(string2,14-length+i,1) else 含有小数的数据其数字对应的单位 onestr(i)=mid(string2,15-length+i+len(thenumber)-checkp,1) end if

one(i)=one(i)&onestr(i)将数字与单位组合 next

money=replace(join(one)," ","") 取得数组中所有的元素,并连接起来 money=replace(money,"零元","元") money=replace(money,"零万","万") money=replace(money,"零亿","亿") money=replace(money,"零仟","零") money=replace(money,"零佰","零") money=replace(money,"零拾","零")

do while not instr(money,"零零")=0 money=replace(money,"零零","零") loop clmoney = moneyend function//***********************************************************

//ip转换成数字,限制ip时用@使用示例// useripnum = ip2num(request.servervariables("remote_addr"))// if useripnum > ip2num("192.168.0.0") and useripnum < // ip2num("192.168.0.255") then// response.write ("<center>您的ip被禁止</center>")// response.end// end if

function ip2num(sip) dim str1,str2,str3,str4 dim num ip2num=0 if isnumeric(left(sip,2)) then str1=left(sip,instr(sip,".")-1) sip=mid(sip,instr(sip,".")+1) str2=left(sip,instr(sip,".")-1) sip=mid(sip,instr(sip,".")+1) str3=left(sip,instr(sip,".")-1) str4=mid(sip,instr(sip,".")+1) num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1 ip2num = num end ifend function//********************************************************

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 我写ASP时常用到的一些函数-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章