Bulletin Board Code (BBCode) – Understanding parsing

computer-keyboard-keys
BBCode itself would be interpreted by a browser as plain text. To not appear as such, but to show a special format, it must first be processed by a parser.

The parser parses the text before submitting the page with a format so that it can be interpreted. A parser specifically looks for BBCode tags and replaces them with the appropriate HTML tags, first doing an analysis of syntax to check for errors.

For example, the BBCode [b ] [/ b] for bold, item can be replaced by writing the HTML element < b> < / b >.

As a general rule, the parsing is done one way, ie, a forum message is stored in the database forum with the BBCode stably, and every time a browser accesses this particular post the parser translates the BBCode forum before submitting it to browser.

Parsing scripts can be written in different programming languages such as PHP and Perl.

An example of a very basic parser written in PHP would be:

<? php
$ text = preg_replace (“/ [b ] ( *) [ / b ] / Usi . “, ” <b> 1 < / b > ” , $ text );
$ text = preg_replace (“/ [ i ] ( *) [ / i ] / Usi . ” , “<i> 1 < / i > ” , $ text );
$ text = preg_replace (“/ [u ] ( *) [ / u ] / Usi . “, ” <u> 1 < / u> ” , $ text );
$ text = preg_replace (“/ [color = ( . *) ] ( . *) [ / color ] / Usi “, ” <span style=”color:\1″> 2 < / span > ” , $ text );
$ text = preg_replace (“/ [ email = ( . *) ] ( . *) [ / email ] / Usi “, ” <a href=”mailto:\1″> 2 < / a> ” , $ text );
>

Using BBCode

BBCode language has elements that can be grouped into five broad categories :

Modifying the appearance of text
Pictures
hyperlinks
ordered structures
Text blocks especially useful

Modifying the appearance of text

The following simple markers can be used to modify the appearance of text, most of these markers come from HTML and their use is widely distributed in different versions of BBCode:

Format Meaning Appearance
[b ] Bold [/ b] Bold text Bold
[ u] underlined [ / u] underlined text , underlined text
[ i ] Italic [ / i ] Italic Text in italics or italics
[ s ] strikethrough [/ s ] strikethrough Strikethrough Text
[size = 18 ] Size 18 [/ size ] to zoom the text size to 18 puntosNota 1 Size 18

↑ Go to “Size” can be used up to size 30. There are also forums that are sized by default and assigned limits. Example : [size = +3] Default size 19 , size shown 22 [ / size]

Alignment modifiers

The use of BBCode alignment markers may be more or less similar to that of HTML depending on the system used in forums, there are two main mechanisms to align either text, tables or pictures.

[align = alignment ] Content align [/ align] where the alignment attribute can take the following values:

left: to align content to the left.
right: to align content to the right.
center: to center the content .
justify: to justify the content .

['' Line ] Content align [/ align ] , where the attribute replaces the name of the label.

Format Meaning Appearance
[align = "left " ] Content align [/ align] Left align
Content to align
[align = "right" ] Content align [/ align] Align right
Content to align
[align = "center " ] Content align [/ align] Aligns to
center align content
[align = "justify "] Small paragraph that shows the text content justified [/ align] Justifies text content
Small paragraph that shows the text contained justified
[left ] Content align [ / left] Left align
Content to align
[right ] Content align [/ right ] Right-aligns
Content to align
[center ] Content align [/ center] Aligns to
center align content
[ justify] Small paragraph that shows the text content justified [/ justify] Justifies text content
Small paragraph that shows the text contained justified

About these ads