Implementing UBB Code

Source: Internet
Author: User
Tags exit copy expression functions implement regular expression trim
Ubb last time, we talked about how to use the "regular expression" object in ASP to achieve a variety of data validation, the text describes the powerful function of regular expression objects, and then,
Let's take a look at the other features of the regular Expression object. When we surf the internet, especially when browsing various forums, we often meet "UBB code"
The word. What is UBB code? UBB code is a variant of HTML http://www.alixixi.com/program/a/, is Ultimate Bulletin Board (a foreign BBS program, there are many places in the country
Use this program) to adopt a special tag. In order to avoid the user unintentionally or intentionally the HTML code to the Forum attack, each kind of forum basically has blocked the HTM
L Code, but in order to make the forum more "colorful", the forum will be appropriate to open some of the custom tag tag, similar to the HTML tag, such as
"http://www.alixixi.com/program/a/,http://www.alixixi.com/program/a/,[red]http://www.alixixi.com/program/a/,[/ RED] ", so that you can provide some functionality equivalent to the HTML code, but also to avoid a malicious attack on the forum, these customized
All kinds of tag is commonly known as UBB code. Today's trendy forums support UBB code, such as: http://www. Chinaasp. COM (move
Sense Technology Network) is a good forum to support UBB code. Now, let's use the regular expression object together to implement our own colorful UBB code.

First of all, your server side (IIS or PWS) to have a VBScript5.0 support environment, generally refers to the installation of ie5.x can already support the "regular expression" to
It's like.

About common methods of regular expression objects, how to use them, and I am in this magazine "using the regular expression object to implement data validation in ASP"
After a detailed introduction, you can see that article, here, I mainly introduce the implementation of "UBB code" the main regular Expression object method: Replace () side
Method.

The Replace method syntax is as follows:

Describe

Replaces the text found in the regular expression lookup.

Grammar

Object. Replace (string1http://www.alixixi.com/program/a/, string2)

The syntax for the Replace method consists of the following sections:

Partial description

Required for object. Always the name of a RegExp object.

String1 is required. String1 is the string that will be replaced with text.

String2 is required. String2 is a replacement text string.

 

Description

The actual mode of the replaced text is set by the RegExp object's Pattern property.

The Replace method returns a copy of the string1, where the Regexp.pattern text has been replaced with string2. If no matching text is found, it returns
Copy of the original string1.

Next, we're going to make sure what kind of UBB code do we ultimately want to implement? This time we want to implement the UBB code features as follows:

URL Super Link
Add a hyperlink to your message as long as it is nested in the following ways (UBB code is bold).

Http://www.alixixi.com/program/a/www.test.net

In the above example, the UBB code will automatically link to the URL and ensure that the link is open when the user clicks on the new window.

Email links
Add an email hyperlink to your message, just follow the example set (UBB code is bold)

Uestc95@263.net

In the above example, the UBB code automatically generates a link to the e-mail message.

Add image
Add an image to your message, just press the example to set it in (UBB code is bold).



In the example above, the UBB code automatically makes the image appear in your message.

Other tag

And these tag http://www.alixixi.com/program/a/, u small H1 H2 H3 h4 h5 h6 strike Blink sub sup del pre big HTTP://WWW.ALIXIXI.C om/program/a/, these tag functions are equivalent to HTML functionality.

[H1] This is a title [/H1]

[/tag] is a must

Make a paragraph of text appear with color
This is a special tag

[#ff0000] a red word [/#]

#后面跟的颜色的16进制RGB代码, such as Red is ff0000http://www.alixixi.com/program/a/, Green is 00ff00http://www.alixixi.com/program/a/, and Blue is 0000ff.

As with all the other UBB code implementations similar to the above, we use the above UBB code implementation as an example to explain the "regular expression" object's powerful work
Yes.

We mainly use the Replace () method with the corresponding template, you can easily realize the UBB code function, where we mainly used two of their own written functions, the first
A function replacetest, this function implements the function mainly is the "regular expression" object to encapsulate, provides three entry parameters:

Patrn
This parameter passes a matching template for the UBB code.

Str
This parameter passes a string that will be processed in a UBB way, such as the content of the article.

Replstr
This parameter passes a matching HTML code language.

The exit parameter of the Replacetest function is the string after the template matching replacement.

The Replacetest function code is as follows:

Function Replacetest (PATRNHTTP://WWW.ALIXIXI.COM/PROGRAM/A/,STRHTTP://WWW.ALIXIXI.COM/PROGRAM/A/,REPLSTR)

Dim regexhttp://www.alixixi.com/program/a/, str1 ' Set variable.

Str1=trim (str)

Set regEx = New RegExp ' establishes a regular expression.

Regex.pattern = Patrn ' Set mode.

Regex.ignorecase = True ' sets whether case sensitive.

Replacetest = Regex.Replace (str1http://www.alixixi.com/program/a/, Replstr) ' for replacement.

Set regex=nothing ' destroys regular expression objects

End Function

The second function we want to write is: UBB () function. This function is the function of the implementation of a piece of text Ubb function conversion. This function has only one entry parameter
Number:

Str
This parameter passes the string to be processed.

The exit parameter of the UBB function is a string that is processed after UBB code.

The code for the UBB function is as follows: (Detailed comment information in the program)

Function UBB (str)

Dim ihttp://www.alixixi.com/program/a/,temp ' Declare variable

I=1

Temp= ""

Do While InStr (ihttp://www.alixixi.com/program/a/,strhttp://www.alixixi.com/program/a/, "[/]>=1 ') if the end of the string is not reached

If trim (temp) = "" Then

Temp=replacetest ("(\)" (\s+) (\) "http://www.alixixi.com/program/a/,strhttp://www.alixixi.com/program/a/," <i >$2</i> ")" for UBB code template matching and replacement

Else

Temp=replacetest ("(\)" (\s+) (\) "http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/a/," <i >$2</i> ")" for UBB code template matching and replacement

End If

Temp=replacetest ("(\)" (\s+) (\) "http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/a/," <b >$2</b> ")" for UBB code template matching and replacement

Temp=replacetest ("(\[big]) (\s+) (\[/big)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/ A/, "<big>$2</big>") ' to match and replace the template for UBB code

Temp=replacetest ("(\[strike]) (\s+) (\[/strike)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/ program/a/, "<strike>$2</strike>") ' for template matching and replacement of UBB code

Temp=replacetest ("(\[sub]) (\s+) (\[/sub)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/ A/, "<sub>$2</sub>") ' to match and replace the template for UBB code

Temp=replacetest ("(\[sup]) (\s+) (\[/sup)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/ A/, "<sup>$2</sup>")

Temp=replacetest ("(\[pre]) (\s+) (\[/pre)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/ A/, "<pre>$2</pre>")

Temp=replacetest ("(\ ) (\s+) (\) "http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/a/, <u>$2</u>")

Temp=replacetest ("(\[small]) (\s+) (\[/small)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/ program/a/, "<small>$2</small>")

Temp=replacetest ("(\[h1]) (\s+) (\[/H1)" http://www.alixixi.com/program/a/,temphttp://www.alixixi.com/program/a/ , "



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.