Is there any function which replaces params in a string? Something like this:?
Code:
$format_str = "My name is %name."; /* this was set in a
configuration file - config.php */
$str = xprintf($format_str, array(\'name\' => \'Joe\', \'age\' => 150));
/* above is somewhere in main code */
The expected value of $str after the operation is:
My name is Joe.
seems like strtr is what is a builtin function which can do the same. (got this from going thru drupal code).
>> $format_str = "My name is %name.";
My name is %name.
>> strtr($format_str, array(\'%name\' => \'Joe\', \'%age\' => 150))
My name is Joe.
Source
http://stackoverflow.com/questions/967926/php-variable-replacement