我写ASP时常用到的一些函数

80酷酷网    80kuku.com

  函数对于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 & "&"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%> <%=pagesize%>页 <%if page>1 then%><a href="<%=url%>page=1"><font face="webdings">9</font></a> <a href="<%=url%>page=<%=page-1%>"><font face="webdings">7</font></a> <%end if%><%for ipage = startPage to endPageif ipage <> page then%> <a href=""><%=ipage%></a> <%else response.write i&" "end ifnext%><%if (totalPage-page)>4 then%><a href="<%=url%>page=<%=page+1%>"><font face="webdings">8</font></a> <a href="<%=url%>page=<%=totalPage%>"><font face="webdings">:</font></a> <%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, ">", ">") fString = replace(fString, "<", "<") fString = Replace(fString, " ", CHR(32)) '  fString = Replace(fString, " ", CHR(9)) '  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, "
", CHR(10)) HTMLDecode = fString End IfEnd Function'//*************************************************************
'//HTML编码函数Function HTMLEncode(fString) If Not IsNull(fString) Then fString = replace(fString, ">", ">") fString = replace(fString, "<", "<") fString

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: