記得曾經貼過一個ubb代碼轉換為html格式的代碼,前些天讀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,"$2")
objRegExp.Pattern="(/[URL/])(/S+?)(/[//URL/])"
strContent= objRegExp.Replace(strContent,"$2")
'email
objRegExp.Pattern="(/)(/S+/@/S+?)(/[//EMAIL/])"
strContent= objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(/[IMG/])(/S+?)(/[//IMG/])"
strContent=objRegExp.Replace(strContent,"")
objRegExp.Pattern="(/[QUOTE/])(.+?)(/[//QUOTE/])"
strContent=objRegExp.Replace(strContent,"face=""Verdana, Arial"">quote:
objRegExp.Pattern="(/[i/])(.+?)(/[//i/])"
strContent=objRegExp.Replace(strContent,"$2")
objRegExp.Pattern="(/[b/])(.+?)(/[//b/])"
strContent=objRegExp.Replace(strContent,"$2")
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/])/ TARGET=_blank>$2 /isg;
$ThePost =~ s/(/[URL/])(/S+?)(/[//URL/])/ TARGET=_blank>$2 /isg;
$ThePost =~ s/(/)(/S+/@/S+?)(/[//EMAIL/])/ HREF="mailto:$2">$2 /isg;
if (($UBBImages eq "ON") && ($OverrideImages ne "yes")) {
$ThePost =~ s/(/[IMG/])(/S+?)(/[//IMG/])/ /isg;
}
$ThePost =~ s/(/[QUOTE/])(.+?)(/[//QUOTE/])/ face="Verdana, Arial">quote:
$2
/isg;
$ThePost =~ s/(/[i/])(.+?)(/[//i/])/$2/isg;
$ThePost =~ s/(/[b/])(.+?)(/[//b/])/$2/isg;
return ($ThePost);
}
學習Asp的同志,不要放棄對CGI的學習,特別是一些老外的CGI程序,看后對我們的asp編程會有很大的啟發,更多精彩內容,盡在https://js.VeVb.com。
新聞熱點
疑難解答