| 導購 | 订阅 | 在线投稿
分享
 
 
 

UBB代碼~(整理)

來源:互聯網  2004-07-16 10:18:32  評論

在論壇中,我常常要使用到特殊的顯示效果,而要得到這些效果,我們通常都是使用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的書寫,可以在網上搜索,我就不說咯!

在論壇中,我常常要使用到特殊的顯示效果,而要得到這些效果,我們通常都是使用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的書寫,可以在網上搜索,我就不說咯!
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有