- preg_replace_callback: documentation ( source)
<?PHP
const pattern =
"#\{(?:(?<name>\w+))(?:/\}|\}(?<snippet>(?:[^{]*|(?!\{\w+:\})|(?R))*)\{end\})#mu";
$ss = <<<'EOD'
{first} {second}within second{end} {end}
EOD;
function testRun($input ){
echo $input[0];
echo PHP_EOL;
}
preg_replace_callback( pattern ,'testRun',$ss);