<?
function recursiveSplit($string, $layer) {
$err = preg_match_all("/\{(([^{}]*|(?R))*)\}/",$string,$matches);
echo "Elementi trovati: $err<br>";
if($err == FALSE) echo "preg_match_all ERROR<br>";
// iterate thru matches and continue recursive split
if (count($matches) > 1) {
for ($i = 0; $i < count($matches[1]); $i++) {
if (is_string($matches[1][$i])) {
if (strlen($matches[1][$i]) > 0) {
echo "<pre>Layer ".$layer.": ".$matches[1][$i]."</pre><br />";
recursiveSplit($matches[1][$i], $layer + 1);
}
}
}
}
}
$buffer = "{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{aaaaaaaaaaaaaaaaaa{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}";
recursiveSplit($buffer, 0);
output
Elementi trovati:
preg_match_all ERROR
Backtrack limit was exhausted!
this code gives me a PREG_BACKTRACK_LIMIT_ERROR error... but the backtrack limit is set to 100.000.000.
/\{((?>[^{}]*|(?R))*)\}/
as it is used in the recursive example on php.net – Ret