PHP setlocale() Function
Topic: PHP String ReferencePrev|Next
Description
The setlocale()
function sets locale information.
The following table summarizes the technical details of this function.
Return Value: | Returns the current locale settings, or FALSE on failure. The return value depends on the system that PHP is running. |
---|---|
Version: | PHP 4+ |
Tip: In computing, a locale refers to a set of parameters that defines the user's language, country/region, and any special preference that the user wants to see in their user interface.
Syntax
The basic syntax of the setlocale()
function is given with:
The following example shows the setlocale()
function in action.
Example
Run this code »<?php
// Set locale
setlocale(LC_ALL, "en_US");
// Get current locale setting
echo setlocale(LC_ALL, 0);
?>
Parameters
The setlocale()
function accepts the following parameters.
Parameter | Description |
---|---|
category |
Required. It is a named constant specifying the category of the functions affected by the locale setting. Available constants are:
|
locale |
Required. Specifies what country/region to set the locale information to. It can be a string or an array. It is also possible to pass multiple locale string.
|
More Examples
Here're some more examples showing how setlocale()
function actually works:
The following example prints date formatted according to the locale setting.
Example
Run this code »<?php
// Set locale to Dutch
setlocale(LC_ALL, "nl_NL");
// Outputs date according to locale
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 04, 11, 2020));
?>