PHP setlocale()Functions

PHP String 参考手册PHP String Reference Manual

Examples

Set locale to US English, then set it back to system default:

<?php
echo setlocale(LC_ALL,"US");
echo "<br>";
echo setlocale(LC_ALL,NULL);
?>

Run Example »

Definition and Usage

The setlocale() function sets locale information (regional information).

Locale information is the language, currency, time, and other information for a geographic region.

Note:The setlocale() function changes locale information only for the current script.

Tip:You can set locale information to the system default via setlocale(LC_ALL,NULL).

Tip:To get numeric format information, please see thelocaleconv()function.


Syntax

setlocale(constant,location)

Parameters Description
constant Required. Specifies what locale information should be set.

Available constants:

  • LC_ALL - all of the options below
  • LC_COLLATE - sort order
  • LC_CTYPE - character classification and conversion (e.g., all characters uppercase or lowercase)
  • LC_MESSAGES - system message format
  • LC_MONETARY - currency format
  • LC_NUMERIC - numeric format
  • LC_TIME - date and time format
location Required. Specifies what country/region to set the locale information to. Can be a string or an array. Multiple locations can be passed.

If the location 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 above constants, or set according to "LANG".

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

If the location parameter is an array, setlocale() tries each array element until it finds a valid language or region code. This is useful if a region has different names on different systems.

Note:To see all available language codes, visit ourLanguage Code Reference Manual。

Technical Details

Return Value: Returns the current locale setting, or FALSE on failure. The return value depends on the system running PHP.
PHP Version: 4+
Changelog: In PHP 4.2.0, passing constants as strings was deprecated. Use the available constants instead. Passing constants as strings will generate a warning message.

In PHP 4.3.0, multiple locations can be passed.locations。

Since PHP 5.3.0, if a string is passed to the constant parameter instead of one of the LC_ constants, the function throws an E_DEPRECATED notice.


PHP String 参考手册PHP String Reference Manual Other Extensions