假如用户输入了http://aaa.bbb.ccc
下面这个代码将把他的输入转换成http://aaa.bbb.ccc
大家看看正则表达式有多厉害,呵呵。
%26lt;%
'调用这个函数来显示成超联结
Response.Write to_html(s_message)
%%26gt;
%26lt;%
Function to_html(s_string)
to_html = Replace(s_string, %26quot;%26quot;%26quot;%26quot;, %26quot;%26amp;quot;%26quot;)
to_html = Replace(to_html, %26quot;%26lt;%26quot;, %26quot;%26amp;lt;%26quot;)
to_html = Replace(to_html, %26quot;%26gt;%26quot;, %26quot;%26amp;gt;%26quot;)
to_html = Replace(to_html, vbcrlf, %26quot;%26lt;br%26gt;%26quot;)
to_html = Replace(to_html, %26quot;/%26amp;lt;%26quot;, %26quot;%26lt;%26quot;)
to_html = Replace(to_html, %26quot;/%26amp;gt;%26quot;, %26quot;%26gt;%26quot;)
to_html = edit_hrefs(to_html)
End Function
%%26gt;
%26lt;script language=%26quot;javascript1.2%26quot; runat=server%26gt;
function edit_hrefs(s_html){
// 一个使用正则表达式的典范
// 转换文本中所有的超联结和电子邮件格式
s_str = new String(s_html);
s_str = s_str.replace(/\bhttp\:\/\/www(\.[\w+\.\:\/\_]+)/gi,
%26quot;http\:\/\/%26amp;not;¤%26amp;cedil;$1%26quot;);
s_str = s_str.replace(/\b(http\:\/\/\w+\.[\w+\.\:\/\_]+)/gi,
%26quot;%26lt;a href=\%26quot;$1\%26quot;%26gt;$1%26lt;\/a%26gt;%26quot;);
s_str = s_str.replace(/\b(www\.[\w+\.\:\/\_]+)/gi,
%26quot;%26lt;a href=\%26quot;http://$1\%26quot;%26gt;$1%26lt;/a%26gt;%26quot;);
s_str = s_str.replace(/\bhttp\:\/\/%26amp;not;¤%26amp;cedil;(\.[\w+\.\:\/\_]+)/gi,
%26quot;%26lt;a href=\%26quot;http\:\/\/www$1\%26quot;%26gt;http\:\/\/www$1%26lt;/a%26gt;%26quot;);
s_str = s_str.replace(/\b(\w+@[\w+\.?]*)/gi,
%26quot;%26lt;a href=\%26quot;mailto\:$1\%26quot;%26gt;$1%26lt;/a%26gt;%26quot;);
return s_str;
}
%26lt;/script%26gt;
转换文本为超联和Email格式的代码
2001-02-12 10:35:42 作者
相关文章
- · 用JavaMail发送带附件的Email
- · Java中使用XML创建EMAIL模板
- · 引用一个能发email的JavaMail的例子
- · 从outlook导入email地址
- · 怎样在APPLET中发EMAIL
- · 用java实现简单的email正则表达式判断
- · email address 生成图片程序
- · 很实用的一个完整email发送程序
- · 全面測試email的有效性
- · 在jsp中发送email
- · 抓取动网论坛Email地址的一段代码
- · 常用Email组件发送函数
- · 表单递交合法性检测-Email
- · 验证email地址是否合法完整实例
- · 怎样写你自己的EMAIL组件(原理)
- · 用vbscript判断email地址的合法性
- · 简单的检查输入email是否合法程序
- · 检查Email地址的比较完善的正则表达式函数
- · 怎 样 在 APPLET 中 发 EMAIL
- · 用java开发Email工具之发送邮件
