BBCode is an abbreviation for Bulletin Board Code, the lightweight markup language used to format posts in many message boards. The available tags are usually indicated by rectangular brackets surrounding a keyword, and they are parsed by the message board system before being translated into a markup language the web browsers understands, usually HTML or XHTML.
BBCode was devised and put to use in order to provide a safer, easier and more limited way of allowing users to format their messages. Previously, many message boards allowed the users to include HTML, which could be used to break/imitate parts of the layout, or run JavaScript. Some implementations of BBCode have suffered problems related to the way they translate the BBCode into HTML, which could negate the security that was intended to be given by BBCode.
Although the basic tags of BBCode are similar in most internet forum software, there are many variants. Some variants require tags to be in the correct case whilst others are not case-sensitive. Some variants have tags which highlight the formatting of HTML, PHP, SQL and other markup languages and programming languages.
BBCode tags
The following are the most common BBCode tags available to most modern message boards, and are displayed here with their HTML equivalents. However, it should be noted that the effect of these tags can be changed substantially, and the effect may not be identical on all sites using BBCode.
| BBCode | HTML | Effect |
[b]bolded text[/b] |
<b>bolded text</b> |
bolded text |
[i]italicized text[/i] |
<i>italicized text</i> |
italicized text |
[u]underlined text[/u] |
<u>underlined text</u> |
underlined text |
[img]http://upload.wikimedia.org/wikipedia/ commons/thumb/6/63/Wikipedia-logo.png/
150px-Wikipedia-logo.png[/img] |
<img src="http://upload.wikimedia.org/wikipedia/ commons/thumb/6/63/Wikipedia-logo.png/ 150px-Wikipedia-logo.png"
/> |
|
[url=http://wikipedia.org]Wikipedia[/url] |
<a href="http://wikipedia.org">Wikipedia</a> |
Wikipedia |
[quote]quoted text[/quote] |
<blockquote>quoted text</blockquote>(usually implemented in more advanced ways) |
To quote:
|
[code]monospaced text[/code] |
<pre>monospaced text</pre> |
monospaced text |
[size=15]Your Text[/size]("12" is usually standard on message boards. Usually measured in pixels (px)) |
<span style="font-size:15px;">Your Text</span> |
Your Text |
[color=red]Red Text[/color] or [color=#FF0000]Red Text[/color](Can use many different color names or hex codes.) |
<span style="color: #FF0000">Red Text</span> |
Red Text |
[:-)] (Not always enclosed in brackets.)
(And usually other emoticons) |
<img src="Face-smile.gif" alt="" /> | (Specific image and size vary) |
Many message boards include a FAQ with information on how to use their own variants of BBCode.
An example PHP function to convert BBCode to HTML
<?php
function bb2html($strInput)
{
$arrBbcode = array
(
'/\[b\](.+?)\[\/b\]/i',
'/\[i\](.+?)\[\/i\]/i',
'/\[quote\](.+?)\[\/quote\]/i',
'/\[url=(.+?)\](.+?)\[\/url\]/i'
);
$arrHtml = array
(
'<strong>$1</strong>',
'<em>$1</em>',
'<blockquote>$1</blockquote>',
'<a href="$1">$2</a>'
);
return preg_replace($arrBbcode, $arrHtml, $strInput);
}
?>