记得以前贴过一个ubb代码转换为html格式的代码,前几天读ubb的源代码。所以有了这个新的版本。注意,这个版本可能还不能正常使用,详细见注。
这段代码将用户输入的ubb代码转化为html格式,注意,需要script engine 5.0的支持(使
用了regexp对象)
[b]注:pattern中使用()将知道regexp记忆搜索到的值,$1是第一个(),其余类推。但$2的
语法并不被5.0版本的vbscript.dll所支持,我检查了自己机器上的版本(安装过ie 5.5),
发现vbscript.dll的版本为5.50.4629,最后修改日期为12月25日。该版本支持$1之类的语
法,这个简单的改进使regexp的功能逐渐与perl的正则表达式靠近[/b]
function ubbcode(strcontent)
dim objregexp
set objregexp=new regexp
objregexp.ignorecase =true
objregexp.global=true
'url
objregexp.pattern="(\[url\])(http:\/\/\s+?)(\[\/url\])"
strcontent= objregexp.replace(strcontent,"<a href=""$2""
target=_blank>$2</a>")
objregexp.pattern="(\[url\])(\s+?)(\[\/url\])"
strcontent= objregexp.replace(strcontent,"<a href=""http://$2""
target=_blank>$2</a>")
'email
objregexp.pattern="(\[email\])(\s+\@\s+?)(\[\/email\])"
strcontent= objregexp.replace(strcontent,"<a
href=""mailto:$2"">$2</a>")
objregexp.pattern="(\[img\])(\s+?)(\[\/img\])"
strcontent=objregexp.replace(strcontent,"<img src=""$2"">")
objregexp.pattern="(\[quote\])(.+?)(\[\/quote\])"
strcontent=objregexp.replace(strcontent,"<blockquote><font size=1
face=""verdana, arial"">quote:</font><hr>$2<hr></blockquote>")
objregexp.pattern="(\[i\])(.+?)(\[\/i\])"
strcontent=objregexp.replace(strcontent,"<i>$2</i>")
objregexp.pattern="(\[b\])(.+?)(\[\/b\])"
strcontent=objregexp.replace(strcontent,"<b>$2</b>")
set objregexp=nothing
ubbcode=strcontent
end function
原版的转化程序,摘自freeware版本的ubb论坛,可到
http://www.ultimatebb.com/下载(perl cgi方式)
sub ubbcode {
my $thepost = shift;
$thepost =~ s/(\[url\])(http:\/\/\s+?)(\[\/url\])/ <a href="$2"
target=_blank>$2<\/a> /isg;
$thepost =~ s/(\[url\])(\s+?)(\[\/url\])/ <a href="http:\/\/$2"
target=_blank>$2<\/a> /isg;
$thepost =~ s/(\[email\])(\s+\@\s+?)(\[\/email\])/ <a
href="mailto:$2">$2<\/a> /isg;
if (($ubbimages eq "on") && ($overrideimages ne "yes")) {
$thepost =~ s/(\[img\])(\s+?)(\[\/img\])/ <img src="$2"> /isg;
}
$thepost =~ s/(\[quote\])(.+?)(\[\/quote\])/ <blockquote><font size="1"
face="verdana, arial">quote:<\/font><hr>$2<hr><\/blockquote>/isg;
$thepost =~ s/(\[i\])(.+?)(\[\/i\])/<i>$2<\/i>/isg;
$thepost =~ s/(\[b\])(.+?)(\[\/b\])/<b>$2<\/b>/isg;
return ($thepost);
}
学习asp的同志,不要放弃对cgi的学习,特别是一些老外的cgi程序,看后对我们的asp编程
会有很大的启发
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器