欢迎光临
我们一直在努力

转换文本为超联和email格式的代码_asp技巧

建站超值云服务器,限时71元/月

如果用户输入了http://aaa.bbb.ccc
下面这个代码将把他的输入转换成http://aaa.bbb.ccc
大家看看正则表达式有多厉害,呵呵。

<%
    调用这个函数来显示成超联结
    Response.Write to_html(s_message)
%>

<%
Function to_html(s_string)
    to_html = Replace(s_string, """", "&quot;")
    to_html = Replace(to_html, "<", "&lt;")
    to_html = Replace(to_html, ">", "&gt;")
    to_html = Replace(to_html, vbcrlf, "<br>")
    to_html = Replace(to_html, "/&lt;", "<")
    to_html = Replace(to_html, "/&gt;", ">")
    to_html = edit_hrefs(to_html)
End Function
%>

<script language="javascript1.2" runat=server>
function edit_hrefs(s_html){
    // 一个使用正则表达式的典范
    // 转换文本中所有的超联结和电子邮件格式
    s_str = new String(s_html);

    s_str = s_str.replace(/\bhttp\:\/\/www(\.[\w+\.\:\/\_]+)/gi,
        "http\:\/\/&not;¤&cedil;$1");

    s_str = s_str.replace(/\b(http\:\/\/\w+\.[\w+\.\:\/\_]+)/gi,
        "<a href=\"$1\">$1<\/a>");
        
    s_str = s_str.replace(/\b(www\.[\w+\.\:\/\_]+)/gi,
        "<a href=\"http://$1\">$1</a>");
        
    s_str = s_str.replace(/\bhttp\:\/\/&not;¤&cedil;(\.[\w+\.\:\/\_]+)/gi,
        "<a href=\"http\:\/\/www$1\">http\:\/\/www$1</a>");
        
    s_str = s_str.replace(/\b(\w+@[\w+\.?]*)/gi,
        "<a href=\"mailto\:$1\">$1</a>");
        
    
    return s_str;
}
</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 转换文本为超联和email格式的代码_asp技巧
分享到: 更多 (0)

相关推荐

  • 暂无文章