Edit report at https://bugs.php.net/bug.php?id=65321&edit=1
ID: 65321 Comment by: anon at anon dot anon Reported by: nico dot weinreich at gmail dot com Summary: Extend sprintf function by type specifier for uppercase and lowercase Status: Open Type: Feature/Change Request Package: Unknown/Other Function Operating System: All PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Easily done in user land. function foo($s) { $args = func_get_args(); return preg_replace_callback('/%(.)/', function($matches) use(&$args) { switch ($matches[1]) { case '%': return '%'; case 's': return next($args); case 't': return mb_convert_case(next($args), MB_CASE_LOWER); case 'T': return mb_convert_case(next($args), MB_CASE_UPPER); } }, $s); } echo foo('Alla %t på %s', 'Uppslagsord', 'K'); -> Alla uppslagsord på K Previous Comments: ------------------------------------------------------------------------ [2013-07-24 08:10:45] nico dot weinreich at gmail dot com Description: ------------ I'm using sprintf() to realize multi language setup of my projects in a simple way, e.g.: $l['Stichworte'] = 'Uppslagsord'; $l['Alle %s mit %s'] = 'Alla %s på %s'; Base language is german, target language is swedish. On runtime I'm doing something like: echo sprintf(Lang::get("Alle %s mit %s"), Lang::get("Stichworte"), 'K'); So I get for german 'Alle Stichworte mit K' and for swedish 'Alla Uppslagsord på K'. The problem is, in this context the word 'Uppslagsord' has to be in lowercase for swedish. So it would be great, if there are two more type specifiers for sprintf() to allow text transformation, e.g.: %s - the argument is treated as and presented as a string %t - the argument is treated as and presented as a lowercase string %T - the argument is treated as and presented as a uppercase string ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65321&edit=1