I have this function to parse bbcode -> html:
$this->text = preg_replace(array(
\'/\\[b\\](.*?)\\[\\/b\\]/ms\',
\'/\\[i\\](.*?)\\[\\/i\\]/ms\',
If you know exactly that the HTML code you want to de-bbcode was en-bbcoded using your method, than do the following:
Switch the two array you pass to preg_replace.
In the array with the HTML code, do the following for every element: Prepend # to the string. Append #s. Replace \1 (and \2 aso) with (.*?).
For the array with the bbcodes do thefollowing with every element: Remove / at the beginning and /ms at end. Replace \s with . Remove all \. Remove all ?. Replace the first (.*) in the string with $1 and the second with $2.
This should do. If any problems: Ask ;)