PHP 语言的 PHP setlocale() 函数是 PHP 语言中重要的内置函数之一,它有助于设置本地或语言环境信息。 PHP setlocale() 函数通常返回当前的新语言环境,如果语言环境的功能根本没有实现,那么它被认为是 FALSE。 PHP 语言的 setlocale() 函数的区域设置/本地信息可以是货币、语言、时间或任何其他特定于特定地理区域的信息。借助 setlocale() 函数,只能更改新/当前脚本的区域设置。我们还可以使用 setlocale() 函数的特定参数将语言环境信息设置为系统默认值。
广告 该类别中的热门课程 PHP 开发人员 - 专业化 | 8 门课程系列 | 3次模拟测试开始您的免费软件开发课程
网络开发、编程语言、软件测试及其他
语法和参数
php setlocale() 的语法和参数如下:
Setlocale(constant1, location1);
setlocale() 的常量参数: 常量参数是强制参数,在 PHP 语言的 setlocale() 函数内部使用。它指定要设置的区域设置信息。有一些可用的常量参数值有时在 PHP 编程中非常有用。他们是:
- LC_ALL: 意思是“以下所有”
- LC_COLLATE: 意思是“排序”
- LC_CTYPE:表示“字符转换和分类”(例如:所有字符都显示大写或小写)
- LC_MESSAGES:表示“系统消息格式/格式化”
- LC_MONETARY: 意思是“货币/货币格式”
- LC_NUMERIC: 意思是“数字/数字格式”
- LC_TIME: 意思是“时间和日期格式”
setlocale() 的位置参数: PHP 的 setlocale() 函数的位置参数也是 setlocale() 函数中应该使用的重要且强制的参数。它可以轻松指定要将哪个地区/国家设置为区域设置信息。它可以是数组或字符串。只能传递到多个位置。如果位置为 NULL 或空字符串 (“”),则位置值/名称将从与上述常量同名的环境变量值或“LANG”中设置。如果位置值设置为值“0”,则位置的设置不会受到影响,只会返回当前设置。
如果位置值是一个数组,setlocale() 函数将尝试每个数组元素,直到找到有效的区域代码或有效的语言。当且仅当该地区以许多不同的系统或名称为人所知时,这才非常有用。此 setlocale() 函数有许多语言代码可用。
setlocale() 函数在 PHP 中如何工作?
PHP 编程语言的 setlocale() 函数通常通过在两个强制参数的帮助下返回区域设置信息来工作。它只返回区域设置信息/信息。 setlocale() 函数的返回值是当前区域设置,但如果失败,将返回 FALSE。值/返回值将取决于实际运行的 PHP 系统。 setlocale() 需要 PHP 4.0+ 版本才能生成输出。在 PHP 5.3.0 版本中,如果将字符串内容传递给特定的常量参数而不是 LC_constants,则该函数将抛出 E_DREPRECATED 通知。
PHP setlocale() 示例
以下是示例:
示例#1
这是为“US”位置实现 setlocale() 函数的示例。首先创建 PHP 标签来输入我们想要实现的代码。然后在 echo 语句之后使用 hr 标签来打印水平线。然后使用字符串值“USA”创建“location1”变量。然后,location1 变量的值将在 echo 语句的帮助下打印出来。然后是“
”标签用于 echo 语句后打印换行符。然后在带有常量和位置参数的 echo 语句之后使用 PHP 编程语言的 setlocale() 函数。所以它会打印区域设置信息。然后“
”标签仅用于视图的水平线。
代码:
<?php echo "<hr>"; $location1="USA"; echo "Your Location is:".$location1; echo "<br>"; echo "By using the setlocale() function of PHP :: ".setlocale(LC_ALL,"$location1"); echo "<hr>"; ?>
输出:
Example #2
This is the example of implementing the setlocale() function of the PHP Programming Language with the NULL value mentioning. Here at first, PHP tags are used to enter the code for the PHP coding language. Then “
” tags are used two times to print two horizontal lines. Then “loc1” variable is created with NULL values inside of the inverted commas. Then location variable value will be printed with the help of the echo statement and the “loc1” variable value. Then “
” tag is used for the line break purpose just after the echo statement. Then setlocale() PHP function is used just after the echo statement with the two parameters with constant value as LC_ALL and the location variable as NULL. Check the output below once.
Code:
<?php echo "<hr>"; echo "<hr>"; $loc1 ="NULL"; echo "Your Location is: $loc1"; echo "<br>"; echo "By using setlocale() function:".setlocale(LC_ALL,$loc1); echo "<hr>"; echo "<hr>"; ?>
Output:
Example #3
This is the example of implementing setlocale() function for the location value “US” and “NULL” just one after the other. Here at first, three times “
” tags are used to print horizontal lines 3 times just for view purposes. Then setlocale() function is used with the constant parameter “LC_ALL” and Location parameter value as “US”. Then
tag is used just after echo statement to print the line break. Then setlocale() function is used for the Location value “NULL”. Usually, for a NULL value, nothing doesn’t print but here NULL is used just after the usage of “US” in the before setlocale() function. So the output remains the same here just for an instance. Just check out the output so that you will understand.
Code:
<?php echo "<hr>"; echo "<hr>"; echo "<hr>"; echo "This is for the location variable value US :: "; echo setlocale(LC_ALL,"US"); echo "<br>"; echo "At first NULL value produce output as the same previous one <br>"; echo "This is for the location variable value NULL :: "; echo setlocale(LC_ALL,NULL); echo "<hr>"; echo "<hr>"; echo "<hr>"; ?>
Output:
以上是PHP 设置区域设置()的详细内容。更多信息请关注PHP中文网其他相关文章!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

SublimeText3汉化版
中文版,非常好用

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

SublimeText3 Linux新版
SublimeText3 Linux最新版