setlocale – PHP String Functions
Syntax :
Description :
The setlocale() function sets the locale information.
Locale information is currency format, currency symbol, language, monetary, time and other information specific for a geographical area.
Parameter :
- category – This is Required parameter. It tells which locale information should we set. Category is a named constant specifying the category of the functions affected by the locale setting:
- LC_ALL for all of the below
- LC_COLLATE for string comparison, see strcoll()
- LC_CTYPE for character classification and conversion, for example strtoupper()
- LC_MONETARY for localeconv()
- LC_NUMERIC for decimal separator (See also localeconv())
- LC_TIME for date and time formatting with strftime()
- LC_MESSAGES for system responses (available if PHP was compiled with libintl)
- locale – This is Required parameter. Specifies what country/region to set the locale information to. Can be a string or an array. It is possible to pass multiple locations.
[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Locale value, Result OR Output
NULL or 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”.
“0”, the locale setting is not affected just only the current setting is returned.
Array or followed by some 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.
[/table]
Note : On Windows, setlocale(LC_ALL, ”) sets the locale names from the system’s regional/language settings (accessible via Control Panel).
Output :
Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.
ChangeLog :
[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 7.0.0 , Support for the category parameter passed as a string has been removed. Only LC_* constants can be used as of this version.
PHP 5.3.0, This function now throws an E_DEPRECATED notice if a string is passed to the category parameter instead of one o
[/table]
Related articles : localeconv(), fprintf() , number_format()
setlocale() – PHP Functions Example 1 : Set the locale to US English and then back to its original values:
<?php echo setlocale(LC_ALL,"US"); echo "<br>"; echo setlocale(LC_ALL,NULL); ?>
See below is the output of above code in Web browser.
English_United States.1252