[SOLVED] Help with removing bbCode
Moderator: General Moderators
In the example given in the fist post there is actually an obvious pattern in that there is an opening tag '[bbtag:uid]' and a closing tag '[/bbtag:uid]' so it would be quite easy to apply a regex to find the opening tag then everything in between and up to the matching closing tag then replace that with just the text in between.
However there are a few special cases (color= etc..) so the regex needs to be extended slightly (untested)....
So I reckon it could be done with a single (or possibly two) regex without too much hassle.
Code: Select all
$data[$i]['topic_text'] = preg_replace('/\[([^\]]+)](.*?)\[\/\\1]/s', '$2', $data[$i]['topic_text']);Code: Select all
$data[$i]['topic_text'] = preg_replace('/\[(\w+)(?:=[^:]+)?(:[^\]]+)](.*?)\[\/\\1\\2]/s', '$3', $data[$i]['topic_text']);