I need to replace \"{Z}\" with \"test(Z)\" where Z is always an unsigned integer using PHP and regular expressions (unless there\'s a faster way?).
$code=\'{
$code = preg_replace('/\{(\d+)\}/', 'test($1)', $code);
In my experience, preg_replace is much faster than any method of doing replacements using str_replace or strtr.
preg_replace
str_replace
strtr