Replaces placeholders with sanitized values in a string.
$string: A string containing placeholders.
$args: An associative array of replacements to make. Occurrences in $string of any key in $args are replaced with the corresponding value, after sanitization. The sanitization function depends on the first character of the key:
t()
function format_string($string, array $args = array()) {
// Transform arguments before inserting them.
foreach ($args as $key => $value) {
switch ($key[0]) {
case '@':
// Escaped only.
$args[$key] = check_plain($value);
break;
case '%':
default:
// Escaped and placeholder.
$args[$key] = drupal_placeholder($value);
break;
case '!':
}
}
return strtr($string, $args);
}