Answer the question
In order to leave comments, you need to log in
How to strip multiple nested data?
There is a string like:
[quote][quote][quote]a[/quote]b[/quote]c[/quote]
Which needs to be cast to the form:
[quote]c[/quote]
And [quote] can also be [ quote="user"].
Answer the question
In order to leave comments, you need to log in
rextester.com/BCEL28233
Or so https://regex101.com/r/rufOQc/3
$re = <<<'END'
@
\G(?!\A)
(?: [^\[]+ | (?! \[/?quote). )*+ \K
(
\[quote[^\]]*\]
(?: [^\[]+ | (?!\[/?quote). | (?1) )*+
\[/quote\]
)
| \[quote[^\]]*\] \K
@xi
END;
$str = preg_replace($re, '', $str);
For example:
https://regex101.com/r/p2nAN3/1 And then find the last bracket ( strrpos
)
from the middle part and cut it off, and everything in front of it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question