目录

PHP setlocale() 函数

❮ PHP 字符串参考

示例

将区域设置设置为美国英语,然后再次恢复为默认值:

<?php
echo setlocale(LC_ALL,"US");
echo "<br>";
echo setlocale(LC_ALL,NULL);
?>
亲自试一试 »

定义和用法

setlocale() 函数设置区域设置信息。

区域设置信息是特定于地理区域的语言、货币、时间和其他信息。

笔记:setlocale() 函数仅更改当前脚本的区域设置。

提示:可以使用 setlocale(LC_ALL,NULL) 将语言环境信息设置为系统默认值

提示:要获取数字格式信息,请参阅语言环境转换()功能。


语法

setlocale( constant,location)

参数值

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

Available constants:

  • 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
location Required. Specifies what country/region to set the locale information to. Can be a string or an array. It is possible to pass multiple locations.

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. This is very useful if a region is known under different names on different systems.

Note: To view all available language codes, go to our Language code reference.

技术细节

返回值: 返回当前区域设置,失败时返回 FALSE。返回值取决于 PHP 运行的系统。
PHP 版本: 4+
变更日志: PHP 5.3.0 - 如果将字符串传递给持续的参数而不是 LC_ 常量之一,此函数会抛出 E_DREPRECATED 通知。

❮ PHP 字符串参考