I dealt with this problem for quite a long time and would like to completely close the question by supplementing the answer of the respected ZyX.
He suggested an excellent search template, but as Moe said, nested quotes themselves are not processed this way.
To solve this problem, I used a while loop and ZyX's pattern with preg_replace_callback function:
$text =
'
[QUOTE=ctmcn]
[quote="John Doe;1000"]Lorem ipsum dolor sit amet[/quote]
Lorem ipsum dolor sit amet
[/QUOTE]
-----------------------------
[QUOTE="John Doe;103318"]
[QUOTE]
[QUOTE="John-Doe;103318"]
Lorem ipsum dolor sit amet
[/QUOTE]
Lorem ipsum dolor sit amet
[/QUOTE]
Lorem ipsum dolor sit amet
[QUOTE="John-Doe;103318"]
Lorem ipsum dolor sit amet
[/QUOTE]
Lorem ipsum dolor sit amet
[QUOTE="John-Doe;103318"]
Lorem ipsum dolor sit amet
[/QUOTE]
Lorem ipsum dolor sit amet
[/QUOTE]
Lorem ipsum dolor sit amet
----------------------------
[QUOTE="John-Doe;103318"]Lorem ipsum dolor sit amet[/QUOTE]
----------------------------
[QUOTE="Максим;103318"]Lorem ipsum dolor sit amet[/QUOTE]
Lorem ipsum dolor sit amet
'
$text = nestedQuotes($text);
function nestedQuotes($text) {
while (preg_match('#\[quote=?(.*?)\](((?R)|.)*?)\[\/quote\]#is', $text)) {
$text = preg_replace_callback (
'#\[quote=?(.*?)\](((?R)|.)*?)\[\/quote\]#is',
function($m) {
if ($m[1]) {
if (strpos(';', $m[1])) {
list($qname, $qpostid) = str_replace('"', '', explode(";", $m[1]));
if ($qname && !$qpostid) return 'here code with quotet username and without source post_id, LIKE: [qoute="username";]text[/quote]';
if ($qname && $qpostid) return 'here code with quotet username and with source post_id, LIKE: [qoute="username;postid"]text[/quote]';
} else {
$qname = str_replace('"', '', $m[1]);
return 'here code with quotet username and without source post_id [qoute=username]text[/quote]';
}
} else {
return 'here anonymous quote, LIKE: [quote]text/quote]';
}
},
$text
);
echo $text;
}
}
Like this you can beat any level nested and any type quotes.
preg_replace_callback function, allow to use function as replacement parameter, thanks to which, we can find out which response to return based on the form in which the original quote is (is it possible to get the name of the quoted user, id of the quoted message, etc.).
Variable $m is array with captured groups.
$m[0] its all captured pattern.
$m[1] its first captured group
$m[2] its second captured group...
and so on..
But this method has a drawback. The search template is quite "greedy" and on large amounts of text I encountered a problem in the work of php. It does not return any values and does not report any errors.
If anyone adds a more optimal search template that would be the perfect solution.
Hope this help somebody!