This is my function.
class bbcode{
var $bbcode_bb2html;
function __construct($string){
$this->bbcode_bb2html= $string;
}
function bbcode_parse_codes( ){
$this->bbcode_bb2html = preg_replace("#\[code=(.*?)\](.*?)\[/code\]#si", "<pre data-snap-ignore=true class=language-\\1><code>\\2</code></pre>", $this->bbcode_bb2html);
return $this->bbcode_bb2html;
}
}
$content="[code=php]test message[/code]";
$bbcode = new bbcode($content);
echo $bbcode->bbcode_bb2html();
True result
<pre data-snap-ignore=true class=language-php><code>test message</code></pre>
But nested message not work. Sample;
$content="[code=php]test message [code=php]...[/code] bla bla bla[/code]";
$bbcode = new bbcode($content);
echo $bbcode->bbcode_bb2html();
False Result
<pre data-snap-ignore=true class=language-php><code>test message [code=php]...</code></pre> bla bla bla[/code]