在论坛中,我常常要使用到特殊的显示效果,而要得到这些效果,我们通常都是使用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,"$2")
RegExp.Pattern = "(\[URL\])(HTTP:\/\/.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"$2")
RegExp.Pattern = "(\[URL=(HTTP:\/\/.[^\[]*)\])(.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"$3")
RegExp.Pattern = "(\[URL=(.[^\[]*)\])(.[^\[]*)(\[\/URL\])"
strNewValue = RegExp.Replace(strValue,"$3")
RegExp.Pattern = "(\[IMG\])(.[^\[]*)(\[\/IMG\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[IMG=(HTTP:\/\/.[^\[]*)\])(\[\/IMG\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[IMG=(.[^\[]*)\])(\[\/IMG\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[SIZE=([0-9]*)\])(.[^\[]*)(\[\/SIZE\])"
strNewValue = RegExp.Replace(strNewValue,"$3")
RegExp.Pattern = "(\[B\])(.[^\[]*)(\[\/B\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[COLOR=(.[^\[]*)\])(.[^\[]*)(\[\/RED\])"
strNewValue = RegExp.Replace(strNewValue,"$3")
RegExp.Pattern = "(\[RED\])(.[^\[]*)(\[\/RED\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[GREEN\])(.[^\[]*)(\[\/GREEN\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[BLUE\])(.[^\[]*)(\[\/BLUE\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[GRAY\])(.[^\[]*)(\[\/GRAY\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[S\])(.[^\[]*)(\[\/S\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[I\])(.[^\[]*)(\[\/I\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[U\])(.[^\[]*)(\[\/U\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[ALIGN=(.[^\[]*)\])(.[^\[]*)(\[\/ALIGN\])"
strNewValue = RegExp.Replace(strNewValue,"
RegExp.Pattern = "(\[CENTER\])(.[^\[]*)(\[\/CENTER\])"
strNewValue = RegExp.Replace(strNewValue,"
RegExp.Pattern = "(\[EMAIL\])(.[^\[]*)(\[\/EMAIL\])"
strNewValue = RegExp.Replace(strNewValue,"$2")
RegExp.Pattern = "(\[EMAIL=(.[^\[]*)\])(.[^\[]*)(\[\/EMAIL\])"
strNewValue = RegExp.Replace(strNewValue,"$3")
RegExp.Pattern = "(\[FLY\])(.[^\[]*)(\[\/FLY\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[MOVE\])(.[^\[]*)(\[\/MOVE\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[MP=([0-9]*),([0-9]*)\])(.[^\[]*)(\[\/MP\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[FLASH\])(.[^\[]*)(\[\/FLASH\])"
strNewValue = RegExp.Replace(strNewValue,"")
RegExp.Pattern = "(\[QT=([0-9]*),([0-9]*)\])(.[^\[]*)(\[\/QT\])"
strNewValue = RegExp.Replace(strNewValue,"
RegExp.Pattern = "(\[RM=([0-9]*),([0-9]*)\])(.[^\[]*)(\[\/RM\])"
strNewValue = RegExp.Replace(strNewValue,"
")
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,"<","<")
strNewValue = Replace(strNewValue,">",">")
strNewValue = Replace(strNewValue,"'","'")
strNewValue = Replace(strNewValue,"""",""")
strNewValue = Replace(strNewValue,vbCrLf,"
")
strNewValue = Replace(strNewValue," "," ")
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的书写,可以在网上搜索,我就不说咯!

