Introduction
Simple BB code parser is a simple, open source(MIT license) BB code parser written in PHP. It is basically one PHP class to include in your own PHP scripts. Out of the box it supports the following tags.
Supported Tags
- [b] - Bold Text
- [i] - Italic Text
- [u] - Underlined Text
- [s] - Strike through text
- [quote] - Blockquote
- [list] and [*] - Ordered lists
- [url] - Links
- [img] - Images
- [color] - font color
- [size] -font size
Other Features
Furthermore, it will automatically parse the text for email addresses and web addresses and make the clickable. It supports smilies(two out of the box), converts new lines to HTML line breaks, and protects against HTML injection.
How to use it
Using Simple BB code parser is, well simple. Basically, you just need to declare the class and throw some BB code at it. It will take care of the rest
Quick Options
Everything under the "Other Features" section above can be turned off easily. Simply pass in the option to the class constructor. The order of options is convert newlines?, parse similies?,make links clickable?. They all default to true. So the following will not make email@email.com clickable.
Adding Tags
Simple BB code parser of course has a simple method to add new tags. The simpliest is the method addTag($bbTag,$htmlTag). For example, it could be used to add the tag [code]
Or perhaps you want to add more smilies. That is just as simple. Use the method addSmiley($smiley,$url_to_image). So if you wanted :smile: to work like :) than you would do this.
There are two more methods addMapped and addTagWithAttribute, but they are much more advanced. Documentation of those two is coming soon
Download
You can get the current version here
Warning: WARNING: Comments is not properly cleaning input params. in /home/freegam4/public_html/webtech/lib/classes/class.module.inc.php on line 1500
Comments
tets
[list] and [*] parsing does not work.
Well I wonder if [b]here we have the [i]bbcode script[/i] actually running[/b], I hope it is!
Thanks for sharing! This is very useful.
Hi,
Thanks for this cool script, I've been working on something where I store values in an XML file and this is perfect for storing HTML as BBCode rather than breaking the XML with more tag soup.
Worked perfect first time. Thanks.
Andy
Great program!
Thanks, Mike!
Wow... amazing script Brady. (By the way, this is mburt from dynamicdrive.com forums). I tried a php bbcode script on my own, and could only get the basic stuff. I use it on my blogging site (creates blogs): http://livejournal.funpic.org
Great script! These are the classes we need :). Takes allot of work to create by yourself and needs allot of debugging. Hope it workes well!