Recursive BBCode Parsing

前端 未结 2 1829
盖世英雄少女心
盖世英雄少女心 2020-12-21 14:15

I\'m trying to parse BBCode in my script. Now, it works seamelessly, until I try to indent BBCode that\'s more than just bold or underline - such as spoiler, url, font size,

相关标签:
2条回答
  • 2020-12-21 14:57

    As gordon said in comments PHP has a BBCode parser, so no reason to reinvent the wheel.

    The native parser is a PECL package though, so you will have to install it. If that's not an option (for instance due to shared hosting), there is also a PEAR package: http://pear.php.net/package/HTML_BBCodeParser

    In addition to those, you can take a look at forums using BB code source code, and either use their parser, or improve it. There is also several PHP implementations listed at http://www.bbcode.org/implementations.php

    0 讨论(0)
  • 2020-12-21 15:04

    Correctly parsing BBcode using regex is non-trival. The codes may be nested. CODE tags may contain BBCodes which must be ignored by the parser. Certain tags may not appear inside of other tags. etc. However, it can be done. I recently overhauled the BBCode parser for the FluxBB open source forum software. You may want to check it out in action:

    New 2011 FluxBB Parser

    Note that this new parser has not yet been incorporated into the FluxBB codebase.

    0 讨论(0)
提交回复
热议问题