I'm trying to use some BB code, however, i'm having a porblem when it comes to using it recursively (e.g. a quote within a quote).
It works fine if there is just one [ quote][ /quote], but if it was to look like this: [ quote][ quote][ /quote][ /quote], only the first [ quote][ /quote] gets formatted. Is there any way to make my preg_replace recursive?
This is so the rich and powerful get world class models before the rest of us, the reality is dumb politicians and rich people don't realize that dense models are on there way out and MOE models are coming in, meaning after PCI-E 8 spec goes live, we run via streaming world class frontier models on a 16gb graphics card.
Question
PRSBOY
Hey there,
I'm trying to use some BB code, however, i'm having a porblem when it comes to using it recursively (e.g. a quote within a quote).
It works fine if there is just one [ quote][ /quote], but if it was to look like this: [ quote][ quote][ /quote][ /quote], only the first [ quote][ /quote] gets formatted. Is there any way to make my preg_replace recursive?
Here is the code:
$input = nl2br(htmlspecialchars($input)); $input = str_replace(array('\r\n', '\r', '\n'), '<br />', $input); $find = array( "'\[b\](.*?)\[/b\]'is", "'\[i\](.*?)\[/i\]'is", "'\[quote](.+)\[/quote\]'i", ); $replace = array( "<strong>\\1</strong>", "<i>\\1</i>", "Quoting <div class=\"quote\">\\1</div>", ); $output = preg_replace($find, $replace, $input);Link to comment
https://www.neowin.net/forum/topic/779498-recursive-preg-replace/Share on other sites
12 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now