<?php $body = "This question is a {{x}} of {{y}} within SO."; $text = ['possible duplicate', '@21100035']; echo preg_replace_callback('~{{[^{}]++}}~', function($m) use ($text, &$count) { return $text[(int)$count++] ?? $m[0]; }, $body, -1, $count);
You have javascript disabled. You will not be able to edit any code.