|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65321 Extend sprintf function by type specifier for uppercase and lowercase
Submitted: 2013-07-24 08:10 UTC Modified: 2013-07-30 02:05 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nico dot weinreich at gmail dot com Assigned:
Status: Wont fix Package: Strings related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-07-24 08:10 UTC] nico dot weinreich at gmail dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-25 00:24 UTC] anon at anon dot anon
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
 [2013-07-30 02:05 UTC]
-Status: Open +Status: Wont fix -Package: Unknown/Other Function +Package: Strings related
 [2013-07-30 02:05 UTC]
Current PHP does not have default multibyte string module. So it's not feasible.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Aug 11 19:01:30 2020 UTC