ASP為字符串中的網址自動加上鏈接
更新時間:2008年06月25日 17:12:44 作者:
asp下用正則實現字符串中的網址加鏈接的代碼
<%
'字段內網址加上聯(lián)接。
Function ToLink(Str)
Dim RE '正則表達式對象 Dim strContent
If IsNull(Str) Then Str = ""
Set RE = New RegExp '創(chuàng)建正 則表達式對象
With RE
.Global = True '搜索應用于整個字符串
.IgnoreCase = True '搜索不區(qū)分大小寫的
strContent = Str
'***************************************************************
'郵件地址鏈接自動設置
'***************************************************************
.Pattern = "([\w]*)@([\w\.]*)"
strContent = .Replace(strContent, "<A Href='mailto:$1@$2'>$1@$2</A> ")
'***************************************************************
'鏈接自動設置
'***************************************************************
'======根據要求再添加協(xié)議名稱=======
Dim D(3), I
D(0) = "http"
D(1) = "ftp"
D(2) = "news"
D(3) = "mms"
'===================================
For I = 0 To UBound(D)
.Pattern = D(I) + ":\/\/([\w\.]*)"
strContent = .Replace(strContent, "<A Href='" + D(I) + "://$1' target=_blank>" + D(I) + "://$1</A> ")
Next
'***************************************************************
End With
Set RE = Nothing
ToLink = strContent
End Function
%>
'字段內網址加上聯(lián)接。
Function ToLink(Str)
Dim RE '正則表達式對象 Dim strContent
If IsNull(Str) Then Str = ""
Set RE = New RegExp '創(chuàng)建正 則表達式對象
With RE
.Global = True '搜索應用于整個字符串
.IgnoreCase = True '搜索不區(qū)分大小寫的
strContent = Str
'***************************************************************
'郵件地址鏈接自動設置
'***************************************************************
.Pattern = "([\w]*)@([\w\.]*)"
strContent = .Replace(strContent, "<A Href='mailto:$1@$2'>$1@$2</A> ")
'***************************************************************
'鏈接自動設置
'***************************************************************
'======根據要求再添加協(xié)議名稱=======
Dim D(3), I
D(0) = "http"
D(1) = "ftp"
D(2) = "news"
D(3) = "mms"
'===================================
For I = 0 To UBound(D)
.Pattern = D(I) + ":\/\/([\w\.]*)"
strContent = .Replace(strContent, "<A Href='" + D(I) + "://$1' target=_blank>" + D(I) + "://$1</A> ")
Next
'***************************************************************
End With
Set RE = Nothing
ToLink = strContent
End Function
%>
相關文章
asp下sql和access數據庫隨機取10條記錄的代碼newid()
利于搜索從表中隨機取幾條不重復記錄,一般都是10條,我就用了40條,大約的代碼就是下面的了2007-12-12rs.open sql,conn,1,1與rs.open sql,conn,1.3還有rs.open sql,conn,
Rs.Open語法如下:rs.Open Source,ActiveConnection,CursorType,LockType Source為sql語句,ActiveConnection為數據庫連接,CursorType是游標,LockType是數據鎖定類型.2011-01-01如何在 Access 2003 和 Access 2002 中創(chuàng)建 DSN 的連接到 SQLServer 對鏈接表
如何在 Access 2003 和 Access 2002 中創(chuàng)建 DSN 的連接到 SQLServer 對鏈接表...2006-10-10