3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "This is my test string {ABC}. This is test {XYZ}. I am new for PHP {PHP}". $i = 1; echo preg_replace_callback('/\{(.+?)\}/', function (array $match) use (&$i) { return sprintf('{%s %d}', $match[1], $i++); }, $string);

preferences:
38.89 ms | 402 KiB | 5 Q