note 106811 added to function.setlocale

From: Date: Thu, 08 Dec 2011 11:45:42 +0000
Subject: note 106811 added to function.setlocale
Groups: php.notes 
Request: Send a blank email to php-notes+get-184974@lists.php.net to get a copy of this message
If you are looking for a getlocale() function simply pass 0 (zero) as the second parameter to setlocale(). Beware though if you use the category LC_ALL and some of the locales differ as a string containing all the locales is returned: <?php echo setlocale(LC_ALL, 0); // LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C; // LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C echo setlocale(LC_CTYPE, 0); // en_US.UTF-8 setlocale(LC_ALL, "en_US.UTF-8"); echo setlocale(LC_ALL, 0); // en_US.UTF-8 ?> If you are looking to store and reset the locales you could do something like this: <?php $originalLocales = explode(";", setlocale(LC_ALL, 0)); setlocale(LC_ALL, "nb_NO.utf8"); // Do something foreach ($originalLocales as $localeSetting) { if (strpos($localeSetting, "=") !== false) { list ($category, $locale) = explode("=", $localeSetting); } else { $category = LC_ALL; $locale = $localeSetting; } setlocale($category, $locale); } ?> The above works here (Ubuntu Linux) but as the setlocale() function is just wrapping the equivalent system calls, your mileage may vary on the result. ---- Server IP: 85.19.212.230 Probable Submitter: 87.238.44.94 ---- Manual Page -- http://www.php.net/manual/en/function.setlocale.php Edit -- https://master.php.net/note/edit/106811 Del: integrated -- https://master.php.net/note/delete/106811/integrated Del: useless -- https://master.php.net/note/delete/106811/useless Del: bad code -- https://master.php.net/note/delete/106811/bad+code Del: spam -- https://master.php.net/note/delete/106811/spam Del: non-english -- https://master.php.net/note/delete/106811/non-english Del: in docs -- https://master.php.net/note/delete/106811/in+docs Del: other reasons-- https://master.php.net/note/delete/106811 Reject -- https://master.php.net/note/reject/106811 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184974) next »