example
Code: Select all
[b:3k355]bold[/b:3k355]
Code: Select all
[b:3k355]bold[/b:3k355]
Here's v2.0 bbcode in a nutshell:
The problem is that parsing the nestable tags (code, quote, and list) is necessarily slow. There's no way around that, other than not actually bothering to find matching pairs of tags. But if we don;t find matching pairs of tags, users can thrash the layout of an entire page just by hanving an unmatched opening tag in their message.
So, what I did was break down that task into 2 separate steps:
1) Recognizing the tags.
2) Actually replacing the tags with HTML code.
Step 1 is done before we put the post in the database, and step 2 is done at pageview time.
What step 1 does is to replace a matching tag pair with a pair of the same tags, but with the addition of a UID string. Example:becomes [quote:UID] ..... [/quote:UID]. The UID part is currently a 10-character random alphanumeric string. Its length can be tweaked for performance, and I haven't decided what the final value will be yet......
So, the second pass can just blindly run a bunch of str_replace() calls, looking for "[quote:UID]" to replace with the starting quote HTML, and "[/quote:UID]" to replace with the ending quote HTML. This process is quite fast.
Also, the first pass can be very easily reversed for the editpost page - we just run str_replace() and basically strip the UIDs from the tags.
So, now the HTML that's used to generate BBCode is no longer stored in the database. This means that HTML can be changed, or specific tags disabled, at any time by the admin without breaking the reversal process, and with the effects taking place immediately across the whole board, including existing posts.
sparkster wrote:The BBCode UID is unique for each userand is stored in the users table.
This is an amazing description and really makes a lot of sense. I read this yesterday and I thought it was an amazing idea, then I was thinking about it again today and it really sunk in. As far as I know, other forums do not use anything like this, and i can see how this aproach is so much faster when displaying forums. As a programmer, congrats to whoever thought of thistm1000 wrote:this was written by psoTFX or someone else on the development team: