A recursive regexp BBCode parser for PHP 7+ using preg_replace_callback(), based on an example by MrNiceGuy on developers-guide.net. Handles nested tags as well as matching brackets and doesn't stumble across invalid tags.
- PHP 7.2+
requires composer
(note: replace dev-master with a version boundary)
{
	"require": {
		"php": ">=7.2.0",
		"chillerlan/php-bbcode": "dev-master"
	}
}Download the desired version of the package from master or release and extract the contents to your project folder. After that:
- run composer installto install the required dependencies and generate/vendor/autoload.php.
- if you use a custom autoloader, point the namespace chillerlan\BBCodeto the foldersrcof the package
Profit!
- @todo
For an implementation example see the GWBBCoder over here: gw1-database/GWBBCode.
- @todo
The parser may cause some high CPU load, depending on the input. You should never consider to use it somewhere in your output subsystem - encode on input - you'll want a preview anyway. ;)
You may also run into several bugs. In fact, the BBCoder is essentially a tool to squeeze out any PCRE related bug in PHP known to man (and perhaps unknown). Have fun! ;) It is highly recommended to use these php.ini settings, especially to disable the PCRE JIT in PHP7 which is a troublemaker. In case you happen to run into a PCRE related bug, i ask you to open an issue over here along with the bbcode which caused the error and further information.
I don't take responsibility for molten CPUs, smashed keyboards, broken HTML etc.. Use at your own risk!