威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
ASP教程>> ASP基础 应用技巧 数据库相关 ASP类 存储过程 FSO专栏 ASP其他
当前位置:首页 > 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

%>

申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
ASP基础
应用技巧
数据库相关
ASP类
存储过程
FSO专栏
ASP其他

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821