trante
trante

Reputation: 33986

PHP setlocale string

In PHP I was setting my locale like this:

// I simplified code, actually there exists 20 different locales and system selects proper language
$myArray=array('de_DE.utf8', 'de_DE' );
$localeData = "'" . implode("', '", $myArray) . "'";
// $localeData = "'de_DE.utf8', 'de_DE'"
setlocale(LC_TIME, $localeData);

This was working up to now. After hours of debugging I found out that this works:

setlocale(LC_TIME, 'de_DE.utf8', 'de_DE');

Does setlocale's behaviour changed ?
It was easier to set locale as a long string.
But now how can I make setlocale ?
I need to pass every value as a parameter to setlocale ?

(I use PHP 5.4.30 in Apache 2 and Centos 6.5)

Upvotes: 0

Views: 962

Answers (1)

Karl
Karl

Reputation: 833

You can get each value to a seperate variable with this code

$myArray = array('de_DE.utf8', 'de_DE' );
list($a, $b) = $myArray;
echo $a; //de_DE.utf8
echo $b; //de_DE

Now you can do it like this

setlocale(LC_TIME, $a, $b);

Also it should be fine passing the array directly to setlocale like this.

setlocale(LC_TIME, $myArray);

http://php.net/manual/en/function.setlocale.php

Upvotes: 2

Related Questions