服务器之家

服务器之家 > 正文

[推荐]ASP编程通用函数收藏大全

时间:2019-10-13 12:47     来源/作者:asp教程网

本帖将收集和征集最全面的ASP编程应用中通用功能函数,人人为我,我为人人:) 
只要大家每人献出一两条自己收藏已久,精典的通用函数,我想本帖将会对许许多多的ASP编程爱好者、工作者有很大的帮助,也将成为大家ASP编程的必备函数集。 
赶快检查您自己的函数库吧,看一下你有的我们这里都有了吗? 
如果你发现了你的函数库里还有着那么一两条鲜为人知的函数,那快点以下面格式跟帖回复吧。 
发表通用函数帖子格式:

复制代码代码如下:

<% 
'****************************** 
'函数:Function RndIP(s) 
'参数:s,四个随机生成的IP头,如"218$211$61$221" 
'作者:阿里西西 
'日期:2007/7/12 
'描述:随机IP地址生成,返回一个随机IP地址值 
'示例:<%=RndIP("218$211$61$221")%> 
'****************************** 
Function RndIP(s) 
on error resume next 
Dim ip,ip1,ip2,ip3,a,b,c 
if s = "" or ubound(split(s,"$"))<>3 then 
response.write "IP前缀参数设置错误,请返回重新设置后启动程序。" 
response.end 
end if 
Randomize 
ip1 = cInt(254*rnd) 
ip2 = cInt(254*rnd) 
ip3 = cInt(254*rnd) 
b = Int ((3*rnd)+1) 

a=Split(s,"$") 
c=a(b) 
RndIP = (c&"."&ip1&"."&ip2&"."&ip3) 
End Function 
%> 


过滤常用的非法字符

复制代码代码如下:

<%  
'******************************  
'函数:ReplaceBadChar(strChar)  
'参数:strChar,待过滤字符  
'作者:阿里西西  
'日期:2007/7/12  
'描述:过滤常用的非法字符  
'示例:<%=ReplaceBadChar("包含有非法字符的'*示例")%>  
'******************************  
function ReplaceBadChar(strChar)  
 if strChar="" then  
  ReplaceBadChar=""  
 else  
  ReplaceBadChar=replace(replace(replace(replace(replace(replace(replace(strChar,"'",""),"*",""),"?",""),"(",""),")",""),"<",""),".","")  
 end if  
end function  
%> 


格式化HTML字符显示

复制代码代码如下:

<%  
'******************************  
'函数:HTMLEncode(fString)  
'参数:fString,待格式化字符串  
'作者:阿里西西  
'日期:2007/7/12  
'描述:格式化HTML字符显示  
'示例:<%=HTMLEncode(fString)%>  
'******************************  
function HTMLEncode(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, CHR(10) & CHR(10), "  ")  
    fString = Replace(fString, CHR(10), "  ")  
    HTMLEncode = fString  
end if  
end function  
%> 


生成不重复的随机数,通常应用于静态HTML生成的文件名

复制代码代码如下:

<%  
'******************************  
'函数:GetNewFileName  
'参数:无  
'作者:阿里西西  
'日期:2007/7/12  
'描述:生成不重复的随机数,通常应用于静态HTML生成的文件名  
'示例:<%=GetNewFileName()%>  
'******************************  
Function GetNewFileName()  
 dim ranNum  
 dim dtNow  
 dtNow=Now()  
 ranNum=int(90000*rnd)+10000  
 GetNewFileName=year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum  
End Function  
%> 


邮件地址验证函数

复制代码代码如下:

<%  
'******************************  
'函数:IsValidEmail(email)  
'参数:email,待验证的邮件地址  
'作者:阿里西西  
'日期:2007/7/12  
'描述:邮件地址验证  
'示例:<%=IsValidEmail(alixixi@msn.com)%>  
'******************************  
function IsValidEmail(email)  
 dim names, name, i, c  
 IsValidEmail = true  
 names = Split(email, "@")  
 if UBound(names) <> 1 then  
    IsValidEmail = false  
    exit function  
 end if  
 for each name in names  
  if Len(name) <= 0 then  
   IsValidEmail = false  
      exit function  
  end if  
  for i = 1 to Len(name)  
      c = Lcase(Mid(name, i, 1))  
   if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then  
         IsValidEmail = false  
         exit function  
       end if  
    next  
    if Left(name, 1) = "." or Right(name, 1) = "." then  
       IsValidEmail = false  
       exit function  
    end if  
 next  
 if InStr(names(1), ".") <= 0 then  
  IsValidEmail = false  
    exit function  
 end if  
 i = Len(names(1)) - InStrRev(names(1), ".")  
 if i <> 2 and i <> 3 then  
    IsValidEmail = false  
    exit function  
 end if  
 if InStr(email, "..") > 0 then  
    IsValidEmail = false  
 end if  
end function  
%>



区分中英文长度,限长截断标题字符

复制代码代码如下:

<%  
'******************************  
'函数:InterceptString(txt,length)  
'参数:txt,待判断截取的标题字符串;length,标题长度  
'作者:阿里西西  
'日期:2007/7/12  
'描述:区分中英文,限长截断标题字符  
'示例:<%=InterceptString("欢迎光临阿里西西WEB开发网站",8)%>  
'******************************  
Function InterceptString(txt,length)  
 dim x,y,ii  
 txt=trim(txt)  
 x = len(txt)  
 y = 0  
 if x >= 1 then  
  for ii = 1 to x  
   if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字  
    y = y + 2  
   else  
    y = y + 1  
   end if  
   if y >= length then  
    txt = left(trim(txt),ii) '字符串限长  
    exit for  
   end if  
  next  
  InterceptString = txt  
 else  
  InterceptString = ""  
 end if  
End Function  
%>

 

复制代码代码如下:

<% 
'****************************** 
'函数:strLength(str) 
'参数:str,待判断长度的字符串 
'作者:阿里西西 
'日期:2007/7/12 
'描述:求字符串长度。汉字算两个字符,英文算一个字符 
'示例:<%=strLength("欢迎光临阿里西西")%> 
'****************************** 
function strLength(str) 
 ON ERROR RESUME NEXT 
 dim WINNT_CHINESE 
 WINNT_CHINESE    = (len("中国")=2) 
 if WINNT_CHINESE then 
        dim l,t,c 
        dim i 
        l=len(str) 
        t=l 
        for i=1 to l 
         c=asc(mid(str,i,1)) 
            if c<0 then c=c+65536 
            if c>255 then 
                t=t+1 
            end if 
        next 
        strLength=t 
    else  
        strLength=len(str) 
    end if 
    if err.number<>0 then err.clear 
end function 
%>

 

复制代码代码如下:

采集获取远程页面的内容<% 
'****************************** 
'函数:GetURL(url)  
'参数:url,远程页面的网址,必须输入完整格式的网址 
'作者:阿里西西 
'日期:2007/7/12 
'描述:采集获取远程页面的内容,很多小偷和采集程序都用到 
'示例:<%=GetURL(http://www.alixixi.com/index.html)%> 
'****************************** 
Function GetURL(url)  
Set Retrieval = CreateObject("Microsoft.XMLHTTP")  
With Retrieval  
.Open "GET", url, False 
.Send  
GetURL = bytes2bstr(.responsebody) 
'对取得信息进行验证,如果信息长度小于100则说明截取失败 
if len(.responsebody)<100 then 
response.write "获取远程文件 <a href="&url&" target=_blank>"&url&"</a> 失败。" 
response.end 
end if 
End With  
Set Retrieval = Nothing  
End Function 
' 二进制转字符串,否则会出现乱码的! 
function bytes2bstr(vin)  
strreturn = ""  
for i = 1 to lenb(vin)  
thischarcode = ascb(midb(vin,i,1))  
if thischarcode < &h80 then  
strreturn = strreturn & chr(thischarcode)  
else  
nextcharcode = ascb(midb(vin,i+1,1))  
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))  
i = i + 1  
end if  
next  
bytes2bstr = strreturn  
end function  
%> 
标签:

相关文章

热门资讯

玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情 2019-06-22
抖音撒撒累累是什么歌 撒撒累累张艺兴歌曲名字
抖音撒撒累累是什么歌 撒撒累累张艺兴歌曲名字 2019-06-05
超A是什么意思 你好a表达的是什么
超A是什么意思 你好a表达的是什么 2019-06-06
返回顶部

437
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40