ASP为字符串中的网址自动加上链接
程序员文章站
2022-07-01 23:35:09
<% '字段内网址加上联接。 function tolink(str) dim re '...
<%
'字段内网址加上联接。
function tolink(str)
dim re '正则表达式对象 dim strcontent
if isnull(str) then str = ""
set re = new regexp '创建正 则表达式对象
with re
.global = true '搜索应用于整个字符串
.ignorecase = true '搜索不区分大小写的
strcontent = str
'***************************************************************
'邮件地址链接自动设置
'***************************************************************
.pattern = "([\w]*)@([\w\.]*)"
strcontent = .replace(strcontent, "<a href='mailto:$1@$2'>$1@$2</a> ")
'***************************************************************
'链接自动设置
'***************************************************************
'======根据要求再添加协议名称=======
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
%>
'字段内网址加上联接。
function tolink(str)
dim re '正则表达式对象 dim strcontent
if isnull(str) then str = ""
set re = new regexp '创建正 则表达式对象
with re
.global = true '搜索应用于整个字符串
.ignorecase = true '搜索不区分大小写的
strcontent = str
'***************************************************************
'邮件地址链接自动设置
'***************************************************************
.pattern = "([\w]*)@([\w\.]*)"
strcontent = .replace(strcontent, "<a href='mailto:$1@$2'>$1@$2</a> ")
'***************************************************************
'链接自动设置
'***************************************************************
'======根据要求再添加协议名称=======
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循环行数输出函数