youthweb / bbcode-parser
BBCode-to-HTML parser
Requires
- php: ^7.4 || ^8.0
- cache/void-adapter: ^1.1
- jakeasmith/http_build_url: ^1
- jbbcode/jbbcode: ^1.4
- youthweb/urllinker: ^1.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-24 22:26:58 UTC
README
A BBCode-to-HTML parser for youthweb.net
Install
Via Composer
$ composer require youthweb/bbcode-parser
Usage
The library has two parts that run side by side:
- The engine (
Engine) is the default for new code. It is built on league/commonmark, renders BBCode and Markdown and writes valid HTML. - The parser (
Manager) is the original implementation. It stays for compatibility with existing code.
The API of the engine is @experimental until the marks are removed, see the backward compatibility promise. The API of the parser is covered by the promise.
Engine (default)
The input mode is chosen per call: a text is either BBCode or Markdown.
use Youthweb\BBCodeParser\Engine; use Youthweb\BBCodeParser\InputMode; $engine = new Engine(); echo $engine->toHtml('This is a [i]simple[/i] test to demonstrate the [b]BBCodeParser[/b].'); // "<p>This is a <em>simple</em> test to demonstrate the <strong>BBCodeParser</strong>.</p>" echo $engine->toHtml('This is a *simple* test to demonstrate the **BBCodeParser**.', InputMode::Markdown); // "<p>This is a <em>simple</em> test to demonstrate the <strong>BBCodeParser</strong>.</p>"
Parser (compatibility)
Manager renders BBCode only and takes the config keys, filters and visitors of the original implementation.
use Youthweb\BBCodeParser\Manager; $text = '[h1]Hello World![/h1] This is a [i]simple[/i] test to demonstrate the [b]BBCodeParser[/b].'; $parser = new Manager(); $config = ['parse_headlines' => true]; echo $parser->parse($text, $config); // "<h1>Hello World!</h1> // <p>This is a <i>simple</i> test to demonstrate the <b>BBCodeParser</b>.</p>"
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ vendor/bin/phpunit
Contributing
Please feel free to submit bugs or to fork and sending Pull Requests.
License
GPL3. Please see License File for more information.