FormatRemoteUrl函數(shù)之a(chǎn)sp實現(xiàn)格式化成當(dāng)前網(wǎng)站完整的URL-將相對地址轉(zhuǎn)換為絕對地址的代碼
更新時間:2007年09月01日 22:09:04 作者:
'================================================
'函數(shù)名:FormatRemoteUrl
'作 用:格式化成當(dāng)前網(wǎng)站完整的URL-將相對地址轉(zhuǎn)換為絕對地址
'參 數(shù): url ----Url字符串
'參 數(shù): CurrentUrl ----當(dāng)然網(wǎng)站URL
'返回值:格式化取后的Url
'================================================
Public Function FormatRemoteUrl(ByVal URL,ByVal CurrentUrl)
Dim strUrl
If Len(URL) < 2 Or Len(URL) > 255 Or Len(CurrentUrl) < 2 Then
FormatRemoteUrl = vbNullString
Exit Function
End If
CurrentUrl = Trim(Replace(Replace(Replace(Replace(Replace(CurrentUrl, "'", vbNullString), """", vbNullString), vbNewLine, vbNullString), "\", "/"), "|", vbNullString))
URL = Trim(Replace(Replace(Replace(Replace(Replace(URL, "'", vbNullString), """", vbNullString), vbNewLine, vbNullString), "\", "/"), "|", vbNullString))
If InStr(9, CurrentUrl, "/") = 0 Then
strUrl = CurrentUrl
Else
strUrl = Left(CurrentUrl, InStr(9, CurrentUrl, "/") - 1)
End If
If strUrl = vbNullString Then strUrl = CurrentUrl
Select Case Left(LCase(URL), 6)
Case "http:/", "https:", "ftp://", "rtsp:/", "mms://"
FormatRemoteUrl = URL
Exit Function
End Select
If Left(URL, 1) = "/" Then
FormatRemoteUrl = strUrl & URL
Exit Function
End If
If Left(URL, 3) = "../" Then
Dim ArrayUrl
Dim ArrayCurrentUrl
Dim ArrayTemp()
Dim strTemp
Dim i, n
Dim c, l
n = 0
ArrayCurrentUrl = Split(CurrentUrl, "/")
ArrayUrl = Split(URL, "../")
c = UBound(ArrayCurrentUrl)
l = UBound(ArrayUrl) + 1
If c > l + 2 Then
For i = 0 To c - l
ReDim Preserve ArrayTemp(n)
ArrayTemp(n) = ArrayCurrentUrl(i)
n = n + 1
Next
strTemp = Join(ArrayTemp, "/")
Else
strTemp = strUrl
End If
URL = Replace(URL, "../", vbNullString)
FormatRemoteUrl = strTemp & "/" & URL
Exit Function
End If
strUrl = Left(CurrentUrl, InStrRev(CurrentUrl, "/"))
FormatRemoteUrl = strUrl & Replace(URL, "./", vbNullString)
Exit Function
End Function
'函數(shù)名:FormatRemoteUrl
'作 用:格式化成當(dāng)前網(wǎng)站完整的URL-將相對地址轉(zhuǎn)換為絕對地址
'參 數(shù): url ----Url字符串
'參 數(shù): CurrentUrl ----當(dāng)然網(wǎng)站URL
'返回值:格式化取后的Url
'================================================
Public Function FormatRemoteUrl(ByVal URL,ByVal CurrentUrl)
Dim strUrl
If Len(URL) < 2 Or Len(URL) > 255 Or Len(CurrentUrl) < 2 Then
FormatRemoteUrl = vbNullString
Exit Function
End If
CurrentUrl = Trim(Replace(Replace(Replace(Replace(Replace(CurrentUrl, "'", vbNullString), """", vbNullString), vbNewLine, vbNullString), "\", "/"), "|", vbNullString))
URL = Trim(Replace(Replace(Replace(Replace(Replace(URL, "'", vbNullString), """", vbNullString), vbNewLine, vbNullString), "\", "/"), "|", vbNullString))
If InStr(9, CurrentUrl, "/") = 0 Then
strUrl = CurrentUrl
Else
strUrl = Left(CurrentUrl, InStr(9, CurrentUrl, "/") - 1)
End If
If strUrl = vbNullString Then strUrl = CurrentUrl
Select Case Left(LCase(URL), 6)
Case "http:/", "https:", "ftp://", "rtsp:/", "mms://"
FormatRemoteUrl = URL
Exit Function
End Select
If Left(URL, 1) = "/" Then
FormatRemoteUrl = strUrl & URL
Exit Function
End If
If Left(URL, 3) = "../" Then
Dim ArrayUrl
Dim ArrayCurrentUrl
Dim ArrayTemp()
Dim strTemp
Dim i, n
Dim c, l
n = 0
ArrayCurrentUrl = Split(CurrentUrl, "/")
ArrayUrl = Split(URL, "../")
c = UBound(ArrayCurrentUrl)
l = UBound(ArrayUrl) + 1
If c > l + 2 Then
For i = 0 To c - l
ReDim Preserve ArrayTemp(n)
ArrayTemp(n) = ArrayCurrentUrl(i)
n = n + 1
Next
strTemp = Join(ArrayTemp, "/")
Else
strTemp = strUrl
End If
URL = Replace(URL, "../", vbNullString)
FormatRemoteUrl = strTemp & "/" & URL
Exit Function
End If
strUrl = Left(CurrentUrl, InStrRev(CurrentUrl, "/"))
FormatRemoteUrl = strUrl & Replace(URL, "./", vbNullString)
Exit Function
End Function
您可能感興趣的文章:
相關(guān)文章
asp實現(xiàn)讀取數(shù)據(jù)庫輸出json代碼
這篇文章主要介紹了asp實現(xiàn)讀取數(shù)據(jù)庫輸出json代碼的方法的相關(guān)資料,需要的朋友可以參考下2015-03-03asp(JavaScript)自動判斷網(wǎng)頁編碼并轉(zhuǎn)換的代碼
asp轉(zhuǎn)換網(wǎng)頁編碼的代碼,用正則匹配頁面的編碼聲明是gb2312還是別的,然后輸出。2010-06-06asp 實現(xiàn)當(dāng)有新信息時播放語音提示的效果
最近做一套程序的時候,客戶要求當(dāng)有新信息的時候播放一段語音來提示一下,根據(jù)情況,總結(jié)思路如下2009-06-06asp中用insert into語句向數(shù)據(jù)庫插入記錄(添加信息)的方法
asp中用insert into語句向數(shù)據(jù)庫插入記錄信息的方法,學(xué)習(xí)的朋友可以參考下。2010-09-09推薦4款傻瓜型的ASP服務(wù)器軟件(asp運行環(huán)境一鍵搭建工具)
雖然現(xiàn)在各種語言大行其道,但是asp的成熟性以及易用性還是有很大的客戶量存在,要運行ASP程序,必須安裝調(diào)試ASP的環(huán)境,而IIS對于普通用戶來說,安裝起來還是有一定的難度的,這里我來推薦幾款傻瓜型的ASP服務(wù)器軟件,比較適合初級站長。2014-08-08