PHP setlocale() Function

Definition

The setlocale() function sets locale information for the current script.

Locale information is the information specific for a geographical area, for example the money letter, the language.

The locale information can be set to system default with setlocale(LC_ALL,NULL)

Syntax

PHP setlocale() Function has the following syntax.

setlocale(constant,location)

Parameter

ParameterIs RequiredDescription
constantRequired.What locale information should be set.
locationRequired.What country/region to set the locale information to. Can be a string or an array to pass multiple locations.

Locale information

Available value for constant:

  • LC_ALL - All of the below
  • LC_COLLATE - Sort order
  • LC_CTYPE - Character classification and conversion (e.g. all characters should be lower or upper-case)
  • LC_MESSAGES - System message formatting
  • LC_MONETARY - Monetary/currency formatting
  • LC_NUMERIC - Numeric formatting
  • LC_TIME - Date and time formatting

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

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

If the location is an array, setlocale() will try each array element until it finds a valid language or region code.

Return

PHP setlocale() Function returns the current locale settings, or FALSE on failure.

Example

Set the locale to US English and then back to default again:


<?php//www.jav a  2 s  .  c o  m
echo setlocale(LC_ALL,"US");
echo "\n";
echo setlocale(LC_ALL,NULL);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions