English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and Example of PHP setlocale() Function

   PHP String Character String Functions Manual

    The setlocale() function is used to set region information.

Syntax

string setlocale ( int $category , array $locale )

Definition and Usage

Used to set region information

Return Value

Returns the new current region information. If the region setting feature is not implemented on your platform, the specified region setting does not exist, or the category name is invalid, it will return false.

Parameter

Serial NumberParameter and Description
1

constant

Specify what region information should be set.

 Available Constants:

  • LC_ALL - Include all the following options

  • LC_COLLATE - Collation Order

  • LC_CTYPE - Character Category and Conversion (e.g., all characters uppercase or lowercase)

  • LC_MESSAGES - System Message Format

  • LC_MONETARY - Currency Format

  • LC_NUMERIC - Number Format

  • LC_TIME - Date and Time Format

2

location

Specify the country to set the region information to/Region. It 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 constant above or set according to "LANG".
If the location parameter is "0", the location setting is not affected, and only the current setting is returned.
If the location parameter is an array, setlocale() will try each array element until a valid language or region code is found. This is useful if a region has different names on different systems.

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 can be passed.

Since PHP 5.3Starting from version .0, if the constant parameter is a string rather than one of the LC_ constants, the function will throw an E_DEPRECATED notice.

Online Example

Try the following example, set the region to UK, and then set it back to system default:

<?php
    //Set region to UK
   echo setlocale(LC_ALL, "UK");
   echo "<br>";
   //Set back to system default
   echo setlocale(LC_ALL, NULL);
?>
Test and see‹/›

Output Result

C

PHP String Character String Functions Manual