欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

常用函数

程序员文章站 2022-06-07 19:41:29
...

<%
'set cn=fd_cn()
Function fd_cn(fdcn)
set fd_conn = server.CreateObject("adodb.connection")
fd_conn.open fdcn
set fd_cn=fd_conn
End Function

Function fd_rs(fdcn,fdsql)
set fd_rrss = server.CreateObject("adodb.recordset")
fd_rrss.open fdsql,fdcn,1,3
set fd_rs=fd_rrss
End Function

Function fd_free(rscn)
rscn.close
set rscn=nothing
end Function


Public Function ChkMail(ByVal Email)
Dim Rep,Pmail : ChkMail = True : Set Rep = New RegExp
Rep.Pattern = "([.a-zA-Z0-9_-]){2,10}@([a-zA-Z0-9_-]){2,10}(.([a-zA-Z0-9]){2,}){1,4}$"
Pmail = Rep.Test(Email) : Set Rep = Nothing
If Not Pmail Then ChkMail = False
End Function


'[格式化时间(显示)]
'函数名:Format_Time
'作 用:格式化时间(显示)
'参 数:s_Time ---- 时间变量
'参 数:n_Flag ---- 时间样式类型代码
' 1:"yyyy-mm-dd hh:mm:ss"
' 2:"yyyy-mm-dd"
' 3:"hh:mm:ss"
' 4:"yyyy年mm月dd日"
' 5:"yyyymmdd"
' 6:"MM/DD"
'返回值:返回格式化后时间
'示 例:response.write Format_Time(now(),4)
'**************************************************
Public Function Format_Time(ByVal s_Time,ByVal n_Flag)
Dim y, m, d, h, mi, s
Format_Time = ""
If IsDate(s_Time) = False Then Exit Function
y = cstr(year(s_Time))
m = cstr(month(s_Time))
If len(m) = 1 Then m = "0" & m
d = cstr(day(s_Time))
If len(d) = 1 Then d = "0" & d
h = cstr(hour(s_Time))
If len(h) = 1 Then h = "0" & h
mi = cstr(minute(s_Time))
If len(mi) = 1 Then mi = "0" & mi
s = cstr(second(s_Time))
If len(s) = 1 Then s = "0" & s
Select Case n_Flag
Case 1
' yyyy-mm-dd hh:mm:ss
Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
' yyyy-mm-dd
Format_Time = y & "-" & m & "-" & d
Case 3
' hh:mm:ss
Format_Time = h & ":" & mi & ":" & s
Case 4
' yyyy年mm月dd日
Format_Time = y & "年" & m & "月" & d & "日"
Case 5
' yyyymmdd
Format_Time = y & m & d
Case 6
'mm/dd
Format_Time = m & "/" & d
case 7
Format_Time = m & "/" & d & "/" & right(y,2)
End Select
End Function

'========================================
' 常用函数
'========================================


' 截取字符串
Function SUB_STRING(P_Str,P_Len)
if len(P_Str) > P_Len then '判断字符串的长度
SUB_STRING = left(P_Str,P_Len)&"..."
else
SUB_STRING = P_Str
end if
End Function


'过滤HTML代码
Function RemoveHTML(strHTML)

Dim objRegExp, Match, Matches

Set objRegExp = New Regexp

objRegExp.IgnoreCase = True

objRegExp.Global = True

'取闭合的<>

objRegExp.Pattern = "<.+?>"

'进行匹配

Set Matches = objRegExp.Execute(strHTML)

' 遍历匹配集合,并替换掉匹配的项目

For Each Match in Matches

strHtml=Replace(strHTML,Match.Value,"")

Next

RemoveHTML=strHTML

Set objRegExp = Nothing

End Function


'###################################################################################
'功能:替换录入信息中的特殊字符,把他们改为实体符号
'2002/01/04
'###################################################################################
Function Fixit(ByRef Valname)
If Trim(Valname)<>"" Then
Valname=Replace(Valname,chr(34),"“")

Valname=Replace(Valname,"'","''")

Valname=Replace(Valname,".","。")

Valname=Replace(Valname,"<","<")

Valname=Replace(Valname,">",">")

End If
Fixit=Valname
End Function


%>

相关标签: ASP