PHP setlocale() function
Example
Set the locale to US English and then reset it to the system default:
<?php echo setlocale(LC_ALL, "US"); echo "<br>"; echo setlocale(LC_ALL, NULL); ?>
Definition and usage
The setlocale() function sets the locale information (geographical information).
Locale information is specific to a geographic region's language, currency, time, and other information.
Comments:The setlocale() function only changes the locale information for the current script.
Tip:Locale information can be set to the system default by using setlocale(LC_ALL, NULL).
Tip:For information on number formatting, see localeconv() Function.
Syntax
setlocale(constant,location)
Parameter | Description |
---|---|
constant |
Required. Specifies what locale information should be set. Available constants:
|
location |
Required. Specifies which country/region to set the locale information to. It can be a string or an array. Multiple locations can be passed. If location If the parameter is NULL or an empty string "", the location name will be set to the value of the environment variable with the same name as the constant above or set according to "LANG". If location If the parameter is "0", the location setting is not affected, and only the current setting is returned. If location The parameter is an array, and setlocale() will try each array element until it finds a valid language or locale code. This is very useful if a location has different names on different systems. Comments:To view all available language codes, please visit ourLanguage Code Reference Manual. |
Technical Details
Return Value: | Returns the current locale settings, or FALSE on failure. The return value depends on the system running PHP. |
PHP Version: | 4+ |
Update Log: |
In PHP 4.2.0, passing constants as strings is deprecated. Please use the available constants instead. Passing constants as strings will produce a warning message. In PHP 4.3.0, multiple locations could be passed. Since PHP 5.3.0, if passed to constant If the parameter is a string, not one of the LC_ constants, the function will throw an E_DEPRECATED notice. |