3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = 'sample {} test {} string {}'; $count = 0; echo preg_replace_callback("~{}~", function($m) use (&$count) { return '(' . $count++ . ')'; }, $string);

preferences:
54.61 ms | 1361 KiB | 5 Q