当前位置:首页 > ASP教程 > 应用技巧

ASP为字符串中的网址自动加上链接

<%
'字段内网址加上联接。
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

%>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!