This class can be used to convert BBCode style text to html.
This is standalone class whitch uses regular expression rules to parse bbcode. It is simple to use by calling only one static method and supports lots of bbcode style tags (see the table below).
Usage example:
include "BBCode.class.php"; $bbcode_text = 'Hello [b]World[/b]!'; $html_text = BBCode::parse($bbcode_text); echo $html_text;
The output is:
Hello <strong>World</strong>!
[b]{text}[/b] | Makes {text} bold |
[i]{text}[/i] | Makes {text} italic |
[u]{text}[/u] | Makes {text} underlined |
[s]{text}[/s] | Makes {text} strike through |
[size={number}]{text}[/size] | Changes the font-size of {text} |
[font={font-family}]{text}[/font] | Changes the font-family of {text} |
[color={colour}]{text}[/color] | Changes the colour of {text} |
[center]{text}[/center] | Centers {text} on page |
[align={left|center|right}]{text}[/align] | Aligns {text} on page to left, center or right |
[url]{url}[/url] [url={url}]{text}[/url] |
Makes a link or named link to {url} |
[mail]{email}[/mail] [mail={email}]{text}[/mail] |
Makes na e-mail link or named e-mail link to {email} |
[bull /] | Outputs bullet: • |
[copyright /] | Outputs "copyright" symbol: © |
[registered /] | Outputs "registered" symbol: ® |
[tm /] | Outputs "trademark" symbol: ™ |
[img]{url}[/img] |
Shows the image indicated by {url} |
[img={width}x{height}]{url}[/img] |
Shows {url} image resized to {width} and {height} |
[img width={width} height={height} ...]{url}[/img] | Shows {url} image with additional metainformation. You can add attributes supported by the HTML <img> tag. Eg.: width, height, alt, align, etc. |
[quote]quote[/quote] [quote={name}]{text}[/quote] |
Creates a quotation box containing {text} or quotation box quoting {name} as saying {text} |
[code]{text}[/code] | Outputs {text} to a preformatted text block |
[list]{items}[/list] [list={list-style}]{items}[/list] List items: |
Displays a list of {items} Example: [list] [*] Item one [*] Item two [/list] OR [list] [li]Item one[/li] [li]Item two[/li] [/list]Possible {list-style} values: none, disc, circle, square, decimal, decimal-leading-zero, lower-roman, upper-roman, lower-greek, lower-alpha, lower-latin, upper-alpha, upper-latin, hebrew, armenian, georgian, cjk-ideographic, hiragana, katakana, hiragana-iroha, katakana-iroha |
[sub]{text}[/sub] | Makes {text} subscript |
[sup]{text}[/sup] | Makes {text} superscript |
[p]{text}[/p] | Outputs {text} to a paragraph block |
[youtube]{id}[/youtube] | Shows the youtube video indicated by {id} |
[gvideo]{id}[/gvideo] | Shows the google video indicated by {id} |