So I'm currently making a clan web site, and am implementing my own bbcode. Currently, I have an array of regex expressions that replace the bbcode with the appropriate html.
For example
Code: Select all
'/\[color=(.*?)\](.*?)\[\/color\]/' => "<span style='color:\\1'>\\2</span>",
This works, however, it does not support nested tags. If I have a quote tag inside a quote tag it breaks one of the pairs of quotes (I'd also like to prevent some things like quoting youtube videos). Is there a better way to parse the code? I can't just replace each bbcode with the equivalent because we always need a closing tag. What I would have to do is basically loop through the text and replace the bbcode then create a list or queue to keep track of the parsed bbcode. Then track which ones didn't have a closing tag, and either error out or place the closing tag at the end of the post. I'm just not sure how I would keep track of the pairs. Has anyone implemented a similar system have any advice?