Remember to post an UBBCodeConvert the code to HTML format. Read the code of UBB a few days ago.Source code. So with this new version. Note that this version may not work properly yet. For details, see note.
This code converts user-entered UBB code into HTML format. Note that script engine 5.0 is required (
Regexp object used)
Note: Using () in pattern will know the value found in Regexp memory, $1 is the first (), and the rest is similar. But for $2
The syntax is not supported by VBScript. dll of version 5.0. I checked the version on my machine (I installed IE 5.5 ),
It is found that the VBScript. dll version is 5.50.4629, And the last modification date is July 29, December 25. This version supports $1 and other languages.
This simple improvement gradually makes Regexp's function closer to Perl's regular expression.
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 = "(\) (\ s + \ @ \ s + ?) (\ [\/Email \])"
Strcontent = objregexp. Replace (strcontent, "<a href =" "mailto: $2" ">2 2 </a> ")
Objregexp. pattern = "(\ [img \]) (\ s ++ ?) (\ [\/IMG \])"
Strcontent = objregexp. Replace (strcontent, " ")
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
Conversion of the original versionProgram, From the freeware version of The UBB forum, to the http://www.ultimatebb.com/download (Perl CGI Mode)
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/(\) (\ s + \ @ \ s + ?) (\ [\/Email \])/<
Href = "mailto: $2" >2 2 <\/A>/ISG;
If ($ ubbimages EQ "on") & ($ overrideimages ne "yes ")){
$ Thepost = ~ S/(\ [img \]) (\ s + ?) (\ [\/IMG \])//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 );
}
Do not give up learning CGI, especially some foreign CGI programs. It will be very enlightening for ASP programming.