Latest web development tutorials

PHP setlocale () function

PHP String Reference PHP String Reference

Examples

Set region US English, then back to the default:

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

Running instance »

Definition and Usage

setlocale () function to set the locale information (geographic information).

Area information is a geographical area for language, currency, time and other information.

Note: setlocale () function to change the region only information for the current script.

Tip: You can set the default information area by setlocale (LC_ALL, NULL).

Tip: To obtain information in digital format, please see localeconv () function.


grammar

setlocale( constant,location )

参数 描述
constant 必需。规定应该设置什么地区信息。

可用的常量:

  • LC_ALL - 包括下面的所有选项
  • LC_COLLATE - 排序次序
  • LC_CTYPE - 字符类别及转换(例如所有字符大写或小写)
  • LC_MESSAGES - 系统消息格式
  • LC_MONETARY - 货币格式
  • LC_NUMERIC - 数字格式
  • LC_TIME - 日期和时间格式
location 必需。规定把地区信息设置为什么国家/地区。可以是字符串或者数组。可以传递多个位置。

如果 location 参数是 NULL 或空字符串 "",则位置名称会被设置为上面常量中同名的环境变量的值或者根据 "LANG" 进行设置。

如果 location 参数是 "0",则位置设置不受影响,只返回当前的设置。

如果 location 参数是数组,setlocale() 会尝试每个数组元素,直到找到合法的语言或地区代码为止。如果某个地区在不同的系统上拥有不同的名称,这一点很有用。

注释:如需查看所有可用的语言代码,请访问我们的语言代码参考手册

technical details

return value: Returns the current locale, on failure returns FALSE. The return value depends on the operating system PHP.
PHP version: 4+
Update log: In PHP 4.2.0, it has been abandoned to the constant passed as a string is deprecated. Please use the constant instead of the available. The constants passed as a string will produce a warning message.

In PHP 4.3.0, you can pass multiple locations.

Since PHP 5.3.0 onwards, if the parameter is passed to the constant string, rather than one LC_ constants, the function will throw a E_DREPRECATED notice.


PHP String Reference PHP String Reference