PHP setlocale() Function
The setlocale() function in PHP sets locale information(language, monetary, time and, other information specific for a geographical area.)
Syntax
1 2 3 |
setlocale ( int $category , array $locale ) |
Parameter
category(required)- This parameter specified a named constant specifying the category of the functions affected by the locale setting. The constant list is as follow:
- LC_ALL- all of the below
- LC_COLLATE- for string comparison
- LC_CTYPE- for character classification and conversion
- LC_MONETARY- for localeconv()
- LC_NUMERIC- for decimal separator
- LC_TIME- for date and time formatting with strftime()
- LC_MESSAGES- for system responses
location(required)- This parameter specifies what country or region to set the locale information(string or an array). It is also possible to pass multiple locations.
Return
This function returns the new current locale, or FALSE if the specified locale functionality is not implemented on your platform, or if the locale does not exist or the category name is invalid.
Example 1
1 2 3 4 5 6 7 |
<?php //after setting the local information echo "The setlocale() function will return: "; echo setlocale(LC_ALL,NULL); ?> |
Output
1 2 3 |
The setlocale() function will return: en_US.UTF-8 |
Example 2
1 2 3 4 5 6 7 8 9 10 |
<?php //after setting the local information echo "The category LC_MESSAGES return: "; echo setlocale(LC_MESSAGES,NULL); echo "\nThe category LC_CTYPE return: "; // passing no string value echo setlocale(LC_CTYPE," ");// will return no value ?> |
Output
1 2 3 4 |
The category LC_MESSAGES return: en_US.UTF-8 The category LC_CTYPE return: |
Example 3
1 2 3 4 5 6 7 8 |
<?php //after setting the local information echo "The setlocale() function will return: "; /* Set locale to german */ setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu'); ?> |
Output
1 2 3 |
The setlocale() function will return: |