欢迎光临
我们一直在努力

一个新版本的ubb转化程序

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

记得以前贴过一个ubb代码转换为html格式的代码,前几天读ubb的源代码。所以有了这个新的版本。注意,这个版本可能还不能正常使用,详细见注。
这段代码将用户输入的ubb代码转化为html格式,注意,需要script engine 5.0的支持(使
用了regexp对象)

注:pattern中使用()将知道regexp记忆搜索到的值,$1是第一个(),其余类推。但$2的
语法并不被5.0版本的vbscript.dll所支持,我检查了自己机器上的版本(安装过ie 5.5),
发现vbscript.dll的版本为5.50.4629,最后修改日期为12月25日。该版本支持$1之类的语
法,这个简单的改进使regexp的功能逐渐与perl的正则表达式靠近

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编程
会有很大的启发

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