I'm parsing the BBCode using the regex
in order to replace it into the HTML. I'm stuck right now because of the [code]
tags parsing.
Basically, when you do [code][b]this is bb[/b] [u]code in[/u] [i]code[/i][/code]
it shouldnt replace the [b]
, [u]
, [i]
and similar tags that are INSIDE of the [code]
tag.
Unfortunately, using the preg_replace:
$this->_text = preg_replace('/\[i](.+?)\[\/i]/i', '<em>\1</em>', $this->_text);
$this->_text = preg_replace('/\[code](.+?)\[\/code]]/i', '<code>\1</code>', $this->_text);
will cause replacing them all, and the code inside of the [code]
tag will become HTML formated.
Is there any work-around for this? I need ideas. I was thinking about escaping the [
, ]
brackets characters in [code]
before parsing the rest, but this idea sound silly.