Posted on

Parsing BB Code to HTML in custom PHP pages in MyBB


Parsing BB Code to HTML is often required in PHP pages in MyBB. MyBB provides various types of BB code such as [img],,[font] and a lots of BB code but what if you are using MyBB integrated with a different project and you want to use those BB codes in your applications. One of the most difficult situations when you are parsing BB code to PHP in custom pages.

I have the solution for you all, it is very simple and you just need to call the below functions in your custom PHP code and that will enable you to use BB code in your PHP pages.
I have written the PHP code which you will need to copy.

require_once MYBB_ROOT."/inc/class_parser.php";
$parser = new postParser(); </code>
$parser_options = array(
'allow_html' =&gt; 'no',
'allow_mycode' =&gt; 'yes',
'allow_smilies' =&gt; 'yes',
'allow_imgcode' =&gt; 'yes',
'filter_badwords' =&gt; 'yes',
'nl2br' =&gt; 'yes'
$message = $parser-&gt;parse_message($message, $parser_options);
view raw gistfile1.txt hosted with ❤ by GitHub

As you can see,in the first two lines we are calling the inbuilt parser present in MyBB.
After that we are setting the option present in parser function and allowing Mycode in MyBB.
Remember not to enable html in parser options as there has been some issues with MyBB using html in posts which might expose your forums to vulnerability.

Hope this helps you to parse bb code to html in custom php pages, let me know in case of any issues.