<?php
$depth = 0;
$traverse = [0, 0, 0];
$tags = ['table', 'row', 'cell'];
$regex = [];
foreach ($tags as $key=>$tag)
$regex[$key] = '/(\['.$tag.'((?:[\s\.\#]+[a-z]*)*)\]+[^\[]((?:.|\s)*?(?=(?:\['.$tag.')|$)))/';
echo var_export($tags),PHP_EOL;
echo var_export($regex),PHP_EOL;
$content = "[table]
[row]
[cell]
[cell]
[row]
[cell]
[cell]
[table]
[row]
[row]
[cell]
[row]
";
$f_parse = function($matches) use (&$depth, &$traverse, $tags, $regex, &$f_parse) {
$traverse[++$depth]++;
if ($depth < count($regex))
{
preg_replace_callback(
$regex[$depth],
$f_parse,
$matches[0]
);
}
/*
echo "$depth | ${traverse[$depth]} | $tags, ${regex[$depth]}", PHP_EOL;
$result = "";
if ($depth < count($regex))
{
preg_replace_callback(
$regex[$depth],
$f_parse,
$matches[0]
);
}
return $result;*/
echo $depth, ' | ', $traverse[$depth], ' | ', PHP_EOL;
$traverse[$depth--]--;
return $depth;
};
$content = preg_replace_callback(
$regex[$depth],
$f_parse,
$content
);
echo $content, "\n";
?>
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array (
0 => 'table',
1 => 'row',
2 => 'cell',
)
array (
0 => '/(\\[table((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[table)|$)))/',
1 => '/(\\[row((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[row)|$)))/',
2 => '/(\\[cell((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[cell)|$)))/',
)
Warning: Undefined array key 3 in /in/KnMrE on line 27
3 | 1 |
3 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
00
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
0 => 'table',
1 => 'row',
2 => 'cell',
)
array (
0 => '/(\\[table((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[table)|$)))/',
1 => '/(\\[row((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[row)|$)))/',
2 => '/(\\[cell((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[cell)|$)))/',
)
Warning: Undefined array key 3 in /in/KnMrE on line 27
3 | 1 |
3 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
00
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
- array (
0 => 'table',
1 => 'row',
2 => 'cell',
)
array (
0 => '/(\\[table((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[table)|$)))/',
1 => '/(\\[row((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[row)|$)))/',
2 => '/(\\[cell((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[cell)|$)))/',
)
Notice: Undefined offset: 3 in /in/KnMrE on line 27
3 | 1 |
3 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
00
- Output for 7.3.32 - 7.3.33
- array (
0 => 'table',
1 => 'row',
2 => 'cell',
)
array (
0 => '/(\\[table((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[table)|$)))/',
1 => '/(\\[row((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[row)|$)))/',
2 => '/(\\[cell((?:[\\s\\.\\#]+[a-z]*)*)\\]+[^\\[]((?:.|\\s)*?(?=(?:\\[cell)|$)))/',
)
3 | 1 |
3 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
2 | 1 |
3 | 1 |
2 | 1 |
1 | 1 |
00
preferences:
210.01 ms | 402 KiB | 291 Q