Right now I\'m having issues replacing strings that already come out from preg_match. Lets say I have bbcode of [b]bla[/b]
, I have this part working with replacing
You could do something like this:
$string = '[b]hi [b]test[/b][/b]';
do {
$string = preg_replace('/\[b\](.*)\[\/b\]/', '$1', $string, -1, $count);
} while ($count > 0);
Or just use @Justinas' idea (from your OT's comment) if it's OK to replace all [b]
with and
[/b]
with (regardless of them being in the right order/as pairs).
Edit: you also need to change your quote regex to this:
/\[quote(?:=(\d+))?\](.*)\[\/quote\]/s
s
flag allows .
to match newlines (you probably want to add it to the other ones too). I also fixed the quote ID capturing part.