常用函数

来源:互联网 发布:8人捕鱼 源码 编辑:程序博客网 时间:2024/04/25 13:57

' *----------------------------------------------------------------------------
' * 函数:CorrectID
' * 描述:只取数字,过滤字母等
' * 参数:ID
' * 返回:数字
' *----------------------------------------------------------------------------
function CorrectID(ID)
 dim StrLen, i, c, RealID
 StrLen = len(ID)
 RealID = ""
 for i = 1 to StrLen
  c = mid(ID, i, 1)
  if IsNumeric(c) then
   RealID = RealID & c
  else
   i = StrLen
  end if
 next
 if len(RealID) = 0 then
  CorrectID = 0
 else
  CorrectID = RealID
 end if
end function

' *----------------------------------------------------------------------------
' * 函数:GetExtend
' * 描述:获得文件扩展名
' * 参数:文件全名
' * 返回:文件扩展名
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
end function

' *----------------------------------------------------------------------------
' * 函数:CheckIn
' * 描述:检测参数是否有SQL危险字符
' * 参数:str要检测的数据
' * 返回:FALSE:安全 TRUE:不安全
' * 作者:
' * 日期:
' chr (39)单引号 (34)双引号 chr(9) 空格 chr(10)回车 chr(32)空格
' *----------------------------------------------------------------------------
function CheckIn(str)
if instr(1,str,chr(39))>0 or instr(1,str,chr(34))>0 or instr(1,str,chr(59))>0 then
CheckIn=true
else
CheckIn=false
end if
end function

' *----------------------------------------------------------------------------
' * 函数:alertm
' * 描述:在客户端显示消息框
' * 参数:message:要显示的信息
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
Sub alertm(message)
message = replace(message,"'","'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub

' *----------------------------------------------------------------------------
' * 函数:GoBack
' * 描述:在客户端返回上一页
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
Sub GoBack()
Response.write ("<script>history.go(-1)</script>")
End Sub

' *----------------------------------------------------------------------------
' * 函数:Go
' * 描述:重定向另外的连接
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
Sub Go(url)
Response.write ("<script>location.href('" & url & "')</script>")
End Sub

' *----------------------------------------------------------------------------
' * 函数:GoPage
' * 描述:按指定秒数重定向另外的连接
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
sub GoPage(url,s)
s=s*1000
Response.Write "<SCRIPT LANGUAGE=JavaScript>"
Response.Write "window.setTimeout("&chr(34)&"window.navigate('"&url&"')"&chr(34)&","&s&")"
Response.Write "</script>"
end sub

' *----------------------------------------------------------------------------
' * 函数:isInteger
' * 描述:判断数字是否整形
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function isInteger(para)
on error resume next
dim str
dim l,i
if isNUll(para) then
isInteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isInteger=false
exit function
end if
l=len(str)
for i=1 to l
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
end if
next
isInteger=true
if err.number<>0 then err.clear
end function

' *----------------------------------------------------------------------------
' * 函数:HTMLEncode
' * 描述:过滤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 if
end function

' *----------------------------------------------------------------------------
' * 函数:HTMLcode
' * 描述:过滤表单字符
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLcode(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(34), "")
fString = Replace(fString, CHR(10), "<BR>")
HTMLcode = fString
end if
end function

' *----------------------------------------------------------------------------
' * 函数:HTMLREM
' * 描述:解决过滤
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLREM(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "")
fString = Replace(fString, CHR(10), "")
fString=ReplaceSpace(fString)
fString=HTMLEncode(fString)
HTMLREM = fString
end if
end function

' *----------------------------------------------------------------------------
' * 函数:ReplaceSpace
' * 描述:替换所有相连空格为单空格
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function ReplaceSpace(content)
content=trim(content)
if content="" then
replacespace=""
else
while not instr(1,content," ")=0
content=Replace(content," "," ")
wend
replacespace=content
end if
end function

rem 将字串处理成sql中语句的一部分之搜索条件

function StrToSql_or(content,field)
content=trim(content)
if content="" then
strtosql_or=""
else
' and
strtosql_or=field & " like '%" & replace(content," ","%' or " & field & " like '%") & "%'"
end if
end function

rem 将字串处理成sql中语句的一部分之搜索日期
function StrToSql_Date(searchdate,field)
searchdate=clng(searchdate)
select case searchdate
case 0
StrToSql_Date=""
case 1
StrToSql_Date=field & " between '" & dateadd("ww",-1,date()) & "' and '" & date() & "'"
case 2
StrToSql_Date=field & " between '" & dateadd("m",-1,date()) & "' and '" & date() & "'"
case 3
StrToSql_Date=field & " between '" & dateadd("q",-1,date()) & "' and '" & date() & "'"
case 4
StrToSql_Date=field & " between '" & dateadd("yyyy",-1,date()) & "' and '" & date() & "'"
end select
end function

function StrToSql_Date2(field)
dim date_Previous,date_next
date_previous=dateadd("d",-(Weekday(date(),2)-1),(date() & " 1:00:00"))
date_next=dateadd("d",(7-Weekday(date(),2)),(date() & " 23:59:59"))
StrToSql_Date2=field & " between '" & date_previous & "' and '" & date_next & "'"
end function

rem 字符截断
function Strfix(content,n)
content=trim(content)
if len(content)>n then
Strfix=left(content,n) & "..."
else
Strfix=content
end if
end function

rem 字符串处理-截断(新闻)
function StrNewfix(content)
content=trim(content)
if len(content)>27 then
strnewfix=left(content,27) & "..."
else
strnewfix=content
end if
end function

原创粉丝点击