php.net |  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
Votes:1
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
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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] yohgaki@php.net
-Status: Open +Status: Wont fix -Package: Unknown/Other Function +Package: Strings related
 [2013-07-30 02:05 UTC] yohgaki@php.net
Current PHP does not have default multibyte string module. So it's not feasible.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 11:01:30 2024 UTC