PHP- Get current locale

Another answer after two years!

You can simply user Locale::getDefault() or locale_get_default() to get the current locale.

http://php.net/manual/en/locale.getdefault.php

Intl Locale class is the modern alternative for old functions. Once you started using it, you need to update the local by php.net/manual/en/locale.setdefault.php function


You can call setlocale like so, and it'll return the current local.

$currentLocale = setlocale(LC_ALL, 0);
echo $currentLocale; //outputs C/en_US.UTF-8/C/C/C/C on my machine

Here is documentation from php.net as commented by @JROB

locale

If locale is "0", the locale setting is not affected, only the current setting is returned.

If locale is NULL or the empty string "", the locale names will be set from the values of environment variables with the same names as the above categories, or from "LANG".

If locale is an array or followed by additional parameters then each array element or parameter is tried to be set as new locale until success. This is useful if a locale is known under different names on different systems or for providing a fallback for a possibly not available locale.

Tags:

Php