[推薦]ASP編程通用函數(shù)收藏大全
更新時(shí)間:2007年08月08日 10:29:45 作者:
區(qū)分中英文長(zhǎng)度,限長(zhǎng)截?cái)鄻?biāo)題字符
復(fù)制代碼 代碼如下:
<%
'******************************
'函數(shù):InterceptString(txt,length)
'參數(shù):txt,待判斷截取的標(biāo)題字符串;length,標(biāo)題長(zhǎng)度
'作者:阿里西西
'日期:2007/7/12
'描述:區(qū)分中英文,限長(zhǎng)截?cái)鄻?biāo)題字符
'示例:<%=InterceptString("歡迎光臨阿里西西WEB開(kāi)發(fā)網(wǎng)站",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) '字符串限長(zhǎng)
exit for
end if
next
InterceptString = txt
else
InterceptString = ""
end if
End Function
%>
復(fù)制代碼 代碼如下:
<%
'******************************
'函數(shù):strLength(str)
'參數(shù):str,待判斷長(zhǎng)度的字符串
'作者:阿里西西
'日期:2007/7/12
'描述:求字符串長(zhǎng)度。漢字算兩個(gè)字符,英文算一個(gè)字符
'示例:<%=strLength("歡迎光臨阿里西西")%>
'******************************
function strLength(str)
ON ERROR RESUME NEXT
dim WINNT_CHINESE
WINNT_CHINESE = (len("中國(guó)")=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
%>
復(fù)制代碼 代碼如下:
采集獲取遠(yuǎn)程頁(yè)面的內(nèi)容<%
'******************************
'函數(shù):GetURL(url)
'參數(shù):url,遠(yuǎn)程頁(yè)面的網(wǎng)址,必須輸入完整格式的網(wǎng)址
'作者:阿里西西
'日期:2007/7/12
'描述:采集獲取遠(yuǎn)程頁(yè)面的內(nèi)容,很多小偷和采集程序都用到
'示例:<%=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)
'對(duì)取得信息進(jìn)行驗(yàn)證,如果信息長(zhǎng)度小于100則說(shuō)明截取失敗
if len(.responsebody)<100 then
response.write "獲取遠(yuǎn)程文件 <a href="&url&" target=_blank>"&url&"</a> 失敗。"
response.end
end if
End With
Set Retrieval = Nothing
End Function
' 二進(jìn)制轉(zhuǎn)字符串,否則會(huì)出現(xiàn)亂碼的!
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
%>
相關(guān)文章
asp中設(shè)置session過(guò)期時(shí)間方法總結(jié)
asp中默認(rèn)session過(guò)期時(shí)間為20分鐘,很多情況下不夠,今天有客戶(hù)要求很多就要重新登錄了,所以準(zhǔn)備了這篇文章,方便需要的朋友2012-09-09在ASP中不用模板生成HTML靜態(tài)頁(yè)直接生成.html頁(yè)面
有沒(méi)有辦法不用模板,如一個(gè)正常的htmer.asp頁(yè)面,直接生成為htmer.html頁(yè)面呢?當(dāng)然是可以的,而且非常簡(jiǎn)單,今天就教大家在ASP中不用模板生成HTML靜態(tài)頁(yè)的方法2014-09-09如何使用ASP設(shè)置指定站點(diǎn)CPU最大使用程度
如何使用ASP設(shè)置指定站點(diǎn)CPU最大使用程度...2007-01-01asp createTextFile生成文本文件支持utf8
一般情況下可以使用fso的createTextFile函數(shù),但有時(shí)候我們需要生成utf8格式的文件,那么就可以用下面的函數(shù)擴(kuò)展了2020-08-08