- preg_replace_callback: documentation ( source)
<?php
function func($input) {
static $count = 0;
echo (++$count);
return preg_replace_callback('/YO\_\{(.*?)\}/s', 'func', $input);
}
$input = <<<'EOD'
YO_{
YO_{
YO_{
McDonalds.
}
}
}
EOD;
echo func($input);