$tpl = 'Name: {$name}, Surname: {surname}, City: {$person.address.city}';
function tpl2php($m){
$var = $m[1];
if(strpos($var,'.')){
$varArr = explode('.',$var);
$var = $varArr[0];
for($i=1;$i<count($varArr);$i++){
$var .= '["' . $varArr[$i] .'"]';
}
}
return '<?php echo $' . $var . '; ?>';
}
$php = preg_replace_callback('/{\$?([_a-z][\w\.]+[\w])}/iS','tpl2php',$tpl);
// Name: <?php echo $name; ?>, Surname: <?php echo $surname; ?>, City: <?php echo $person["address"]["city"]; ?>