Jump to content
xisto Community

Ultimate Bbcode Tutorial [b ],[ i],[u],[quote ],[img ],smilies

Recommended Posts

This tutorial is really usefull for PHP programmers. I suggest including the original RegEx thingy before the PregEx thingy. Did you get what I said? It's really hard to explain. Again, this is a really usefull tutorial! Good job! -_-

Share this post

Link to post
Share on other sites

Thanks for the great tutorial, this has helped me a ton!


One thing I would recommend adding however is the i modifier. This will make the bbcode case insensitive. For example:


Bold and Bold will both be changed instead of just the first one. To do this, add an "i" after the last slash in each line of the regex statement.



$regexes = array(







Share this post

Link to post
Share on other sites

Is there a way make nested codes work? For example, using the code provided above, if someone types in this:

[colorx=red]red text[colorx=blue]blue text[/colorx]back to red[/colorx]

We "want" this result:

<font color="red">red text<font color="blue">blue text</font>back to red</font>

However, this is the result that the code produces:

<font color="red">red text[colorx=blue]blue text</font>back to red[/colorx]

(note: I used 'colorx' instead of 'color' so the forum would not parse the code)

For the record, different nested codes work, such as italics within bold, but like codes dont work, such as a bold inside of a bold, quote inside of a quote, color inside of a color, etc.

Notice from cmatcmextra:
Please use CODE tags when writing codes. Doing this also prevents the forums from parsing bbcoding.

Edited by cmatcmextra (see edit history)

Share this post

Link to post
Share on other sites
$formated = preg_replace($regexes, $replacements, $text);

You lost me here why do you have to replace the reg in the first place cant you just add a simple image edit to the end to save you the time and trouble of having to update and resend all the information when you go to add a image to the main root?

Share this post

Link to post
Share on other sites

Woah...I've always wondered how BB Code was implemented, that's pretty cool. And yeah, somehow I never knew what preg_replace did...I hadn't even heard about it that much before I read this. Wow, nice tutorial and thanks for the help.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.