Skip to content
Advertisement

PHP setlocale() fails in browser but works in cli

When I run this php file from command line, it is working fine. But running in through the browser, it is not working.

I’m running this on a local virtual Vagrant machine. Running Ubuntu Xenial 16.04 LTS x64.

<?php
$sd = setlocale(LC_TIME, 'nl_NL');
var_dump($sd);
echo strftime("%A");

output:

$ php test.php 
/var/www/domain/test.php:3:
string(5) "nl_NL"
woensdag

Running the same file in te browser:

/var/www/domain/test.php:3:boolean false
Wednesday

I don’t understand why this is happening. I’ve installed the locale.

$ locale -a
C
C.UTF-8
dutch
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US
en_US.iso88591
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
nl_NL
nl_NL.iso88591
nl_NL.utf8
POSIX

Advertisement

Answer

After you install new locales you need to restart PHP for the new locales to work. So try restarting PHP.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement