No regex required:
$s = "String {tag_0} text {tag_2} and {tag_1}";
$myArray = array('a','b','c');
$s = template_subst($s, $myArray);
echo $s;
function template_subst($str, &$arr) {
foreach ($arr as $i => &$v) {
$str = str_replace("{tag_$i}", $v, $str);
}
return $str;
}
source
share