What so ugly about str_replace()
?
function replace_vars($string)
{
$vars = array('NAME'=>'Name', 'VAR2'=>'Value 2', 'VAR3'=>'Value 3');
$names = array();
foreach($vars as $name=>$var) {
$names[] = '{{'.$name.'}';
}
return str_replace($names, $vars, $string);
}
or
function replace_vars($string)
{
$vars = array('{{NAME}}'=>'Name', '{{VAR2}}'=>'Value 2', '{{VAR3}}'=>'Value 3');
return str_replace(array_keys($vars), $vars, $string);
}