Best place to decode bbcode

&nbsp

sned

7:53 pm on Feb 15, 2008 (gmt 0)

I'm curious about people's opinions on where in code to do the actual preg_replace that turns bbcode back into html code.

For example, I have a few fields in a database that store text and bbcode. Right now, I call my bb_decode function anytime I want to display that text on a page (which means the function is scattered all over the place).

Is this how webmasterworld does this kind of thing? Or are there other ways to this?

Thanks! -sned

eelixduppy

8:50 pm on Feb 15, 2008 (gmt 0)

There is less processing if you replace the bbcode with its html counterpart before you add it to the database. This way you only need to do it once.

sned

10:42 pm on Feb 15, 2008 (gmt 0)

I've thought about decoding it before it's entered into the database, then do you just recode the text back to bbcode if the user wants to edit their text and re-submit?

Mohamed

9:43 am on Feb 16, 2008 (gmt 0)

You can parse and replace bbcode on fly before you display the page though it requires more processing than the other methods.

[edited by: Mohamed at 9:48 am (utc) on Feb. 16, 2008]

RonPK

1:09 pm on Feb 17, 2008 (gmt 0)

Right now, I call my bb_decode function anytime I want to display that text on a page (which means the function is scattered all over the place).

If that is the issue, why not put the function in a file which can then be include()d everywhere?