<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      轉換文本為超聯與Email格式的代碼

      [摘要]如果用戶輸入了http://aaa.bbb.ccc下面這個代碼將把他的輸入轉換成http://aaa.bbb.ccc大家看看正則表達式有多厲害,呵呵。<% '調用這個函數來顯示成超聯結 Response.Write to_html(s_message)%><%...
      如果用戶輸入了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>




      日韩精品一区二区三区高清