UBB代码~(整理)

发表于:2007-06-30来源:作者:点击数: 标签:
在论坛中,我常常要使用到特殊的显示效果,而要得到这些效果,我们通常都是使用ubb 函数来处理,下面是我整理的ubb代码~,有待完善~ [CODE] @#----------------------------------------------------------@# @#--------------------UBBCode Function--------
论坛中,我常常要使用到特殊的显示效果,而要得到这些效果,我们通常都是使用ubb 函数来处理,下面是我整理的ubb代码~,有待完善~

[CODE]

@#----------------------------------------------------------@#
@#--------------------UBBCode Function----------------------@#
@#----------------------------------------------------------@#
Function UBBCode(ByVal strValue)
@#忽略错误
On Error Resume Next
@#定义变量
Dim RegExp
Dim strNewValue
Set RegExp = New RegExp
RegExp.IgnoreCase = True
RegExp.Global = True
strValue = UCase(HTMLEncode(strValue))

If strValue <> "" Then
RegExp.Pattern = "(\[URL\])(.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"<A HREF=@#HTTP://$2@# TARGET=@#_BLANK@#>$2</A>")

RegExp.Pattern = "(\[URL\])(HTTP:\/\/.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"<A HREF=@#$2@# TARGET=@#_BLANK@#>$2</A>")

RegExp.Pattern = "(\[URL=(HTTP:\/\/.[^\[]*)\])(.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"<A HREF=@#$2@# TARGET=@#_BLANK@#>$3</A>")

RegExp.Pattern = "(\[URL=(.[^\[]*)\])(.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"<A HREF=@#HTTP://$2@# TARGET=@#_BLANK@#>$3</A>")

RegExp.Pattern = "(\[IMG\])(.[^\[]*)(\[\/IMG\])"
strNewValue = RegExp.Replace(strNewValue,"<IMG SRC=@#$2@# BORDER=@#0@#>")

RegExp.Pattern = "(\[IMG=(HTTP:\/\/.[^\[]*)\])(\[\/IMG\])"
strNewValue = RegExp.Replace(strNewValue,"<IMG SRC=@#$2@# BORDER=@#0@#>")

RegExp.Pattern = "(\[IMG=(.[^\[]*)\])(\[\/IMG\])"
strNewValue = RegExp.Replace(strNewValue,"<IMG SRC=@#HTTP://$2@# BORDER=@#0@#>")

RegExp.Pattern = "(\[SIZE=([0-9]*)\])(.[^\[]*)(\[\/SIZE\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT SIZE=@#$2@#>$3</FONT>")

RegExp.Pattern = "(\[B\])(.[^\[]*)(\[\/B\])"
strNewValue = RegExp.Replace(strNewValue,"<B>$2</B>")

RegExp.Pattern = "(\[COLOR=(.[^\[]*)\])(.[^\[]*)(\[\/RED\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT COLOR=@#$2@#>$3</FONT>")

RegExp.Pattern = "(\[RED\])(.[^\[]*)(\[\/RED\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT COLOR=@##FF0000@#>$2</FONT>")

RegExp.Pattern = "(\[GREEN\])(.[^\[]*)(\[\/GREEN\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT COLOR=@##009900@#>$2</FONT>")

RegExp.Pattern = "(\[BLUE\])(.[^\[]*)(\[\/BLUE\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT COLOR=@##000099@#>$2</FONT>")

RegExp.Pattern = "(\[GRAY\])(.[^\[]*)(\[\/GRAY\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT COLOR=@##999999@#>$2</FONT>")

RegExp.Pattern = "(\[S\])(.[^\[]*)(\[\/S\])"
strNewValue = RegExp.Replace(strNewValue,"<FONT STYLE=@#TEXT-DECORATION:LINE-THROUGH@#>$2</FONT>")

RegExp.Pattern = "(\[I\])(.[^\[]*)(\[\/I\])"
strNewValue = RegExp.Replace(strNewValue,"<I>$2</I>")

RegExp.Pattern = "(\[U\])(.[^\[]*)(\[\/U\])"
strNewValue = RegExp.Replace(strNewValue,"<U>$2</U>")

RegExp.Pattern = "(\[ALIGN=(.[^\[]*)\])(.[^\[]*)(\[\/ALIGN\])"
strNewValue = RegExp.Replace(strNewValue,"<DIV ALIGN=@#$2@#>$3</DIV>")

RegExp.Pattern = "(\[CENTER\])(.[^\[]*)(\[\/CENTER\])"
strNewValue = RegExp.Replace(strNewValue,"<CENTER>$2</CENTER>")

RegExp.Pattern = "(\[EMAIL\])(.[^\[]*)(\[\/EMAIL\])"
strNewValue = RegExp.Replace(strNewValue,"<A HREF=@#MAILTO:$2@#>$2</A>")

RegExp.Pattern = "(\[EMAIL=(.[^\[]*)\])(.[^\[]*)(\[\/EMAIL\])"
strNewValue = RegExp.Replace(strNewValue,"<A HREF=@#MAILTO:$2@#>$3</A>")

RegExp.Pattern = "(\[FLY\])(.[^\[]*)(\[\/FLY\])"
strNewValue = RegExp.Replace(strNewValue,"<MARQUEE SCROLLAMOUT=@#3@# BEHAVIOR=@#ALTERNATE@# WIDTH=@#98%@#>$2</MARQUEE>")

RegExp.Pattern = "(\[MOVE\])(.[^\[]*)(\[\/MOVE\])"
strNewValue = RegExp.Replace(strNewValue,"<MARQUEE SCROLLAMOUT=@#3@#>$2</MARQUEE>")

RegExp.Pattern = "(\[MP=([0-9]*),([0-9]*)\])(.[^\[]*)(\[\/MP\])"
strNewValue = RegExp.Replace(strNewValue,"<OBJECT ALIGN=@#MIDDLE@# CLASSID=@#CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95@# CLASS=@#OBJECT@# ID=@#MEDIAPLAYER@# WIDTH=@#$2@# HEIGHT=@#$3@#><PARAM NAME=@#SHOWSTATUSBAR@# VALUE=@#-1@#><PARAM NAME=@#FILENAME@# VALUE=@#$4@#><EMBED TYPE=@#APPLICATION/X-OLEOBJECT@# CODEBASE=@#HTTP://ACTIVEX.MICROSOFT.COM/ACTIVEX/CONTROLS/MPLAER/EN/NSMP2INF.CAB#VERSION=5,1,52,701@# FILENAME=MP SRC=@#$4@# WIDTH=@#$2@# HEIGHT=@#$3@#></EMBED></OBJECT>")

RegExp.Pattern = "(\[FLASH\])(.[^\[]*)(\[\/FLASH\])"
strNewValue = RegExp.Replace(strNewValue,"<OBJECT CODEBASE=@#HTTP://DOWNLOAD.MACROMEDIA.COM/PUB/SHOCKWAVE/CABS/FLASH/SWFLASH.CAB#VERSION=4,0,2,0@# CLASSID=@#CLSID:D27CDB6E-AE6D-11CF-96B8-444553540000@# WIDTH=@#500@# HEIGHT=@#400@#><PARAM NAME=@#MOVIE@# VALUE=@#$2@#><PARAM NAME=@#QUALITY@# VALUE=@#HIGH@#><EMBED SRC=@#$2@# QUALITY=@#HIGH@# PLUGINSPAGE=@#http://WWW..MACROMEDIA.COM/SHOCKWAVE/DOWNLOAD/INDEX.CGI?P1_PROD_VERSION=SHOCKWAVEFLASH@# TYPE=@#APPLICATION/S-SHOCKWAVE-FLASH@# WIDTH=@#500@# HEIGHT=@#400@#>$2</EMBED></OBJECT>")

RegExp.Pattern = "(\[QT=([0-9]*),([0-9]*)\])(.[^\[]*)(\[\/QT\])"
strNewValue = RegExp.Replace(strNewValue,"<EMBED SRC=@#$4@# WIDTH=@#$2@# HEIGHT=@#$3@# AUTOPLAY=@#TRUE@# LOOP=@#FALS@#E CONTROLLER=@#TRUE@# PLAYEVERYFRAME=@#FALSE@# CACHE=FALSE SCALE=@#TOFIT@# BGCOLOR=@##000000@# KIOSKMODE=@#FALSE@# TARGETCACHE=@#FALSE@# PLUGINSPAGE=@#HTTP://WWW.APPLE.COM/QUICKTIME/@#>")

RegExp.Pattern = "(\[RM=([0-9]*),([0-9]*)\])(.[^\[]*)(\[\/RM\])"
strNewValue = RegExp.Replace(strNewValue,"<OBJECT CLASSID=@#CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA@# CLASS=@#OBJECT@# ID=@#RAOCX@# WIDTH=@#$2@# HEIGHT=@#$3@#><PARAM NAME=@#SRC@# VALUE=@#$4@#><PARAM NAME=@#CONSOLE@# VALUE=@#CLIP1@#><PARAM NAME=@#CONTROLS@# VALUE=@#IMAGEWINDOW@#><PARAM NAME=@#AUTOSTART@# VALUE=@#TRUE@#></OBJECT><BR><OBJECT CLASSID=@#CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA@# HEIGHT=@#32@# ID=@#VIDEO2@# WIDTH=@#$3@#><PARAM NAME=@#SRC@# VALUE=@#$4@#><PARAM NAME=@#AUTOSTART@# VALUE=@#-1@#><PARAM NAME=@#CONTROLS@# VALUE=@#CONTROLPANEL@#><PARAM NAME=@#CONSOLE@# VALUE=@#CLIP1@#></OBJECT>")
End If
UBBCode = LCase(strNewValue)

@#输出错误
If Err.Number>0 Then
Response.Write Err.Description
Response.End
End If
End Function

@#----------------------------------------------------------@#
@#-------------------HTMLEncode Function--------------------@#
@#----------------------------------------------------------@#
Function HTMLEncode(ByVal strValue)
@#忽略错误
On Error Resume Next
@#定义变量
Dim strNewValue
If strValue <> "" Then
strValue = Server.HTMLEncode(strValue)
strNewValue = Replace(strValue,"<","&lt;")
strNewValue = Replace(strNewValue,">","&gt;")
strNewValue = Replace(strNewValue,"@#","&#39;")
strNewValue = Replace(strNewValue,"""","&quot;")
strNewValue = Replace(strNewValue,vbCrLf,"<br>")
strNewValue = Replace(strNewValue," ","&nbsp;")
End If
HTMLEncode = strNewValue

@#输出错误
If Err.Number>0 Then
Response.Write Err.Description
Response.End
End If
End Function

[CODE]

使用的时候,在你的textarea中输入ubb代码,那么,在处理页面直接使用

content = UBBCode(Request.Form("content"))就可以咯~

关于ubb的书写,可以在网上搜索,我就不说咯!


原文转自:http://www.ltesting.net