PHP Conference Japan 2024

Locale::getDefault

locale_get_default

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

Locale::getDefault -- locale_get_default從 INTL 全域變數 'default_locale' 取得預設地區設定值

說明

物件導向風格

public static Locale::getDefault(): 字串

程序式風格

locale_get_default(): 字串

取得預設地區設定值。在 PHP 初始化時,如果 php.ini 中存在 'intl.default_locale' 值,則此值會設定為該值,否則會從 ICU 的函式 uloc_getDefault() 取得。

參數

回傳值

目前的執行階段地區設定

範例

範例 #1 locale_get_default() 範例

<?php
ini_set
('intl.default_locale', 'de-DE');
echo
locale_get_default();
echo
'; ';
locale_set_default('fr');
echo
locale_get_default();
?>

範例 #2 物件導向範例

<?php
ini_set
('intl.default_locale', 'de-DE');
echo
Locale::getDefault();
echo
'; ';
Locale::setDefault('fr');
echo
Locale::getDefault();
?>

上述範例將輸出

de-DE; fr

另請參閱

新增註釋

使用者貢獻的註釋 1 則註釋

tjsturos
5 年前
即使您沒有進行任何設定,仍然可以呼叫這些方法並取得伺服器的預設語系。

在 Linux (Ubuntu 16.04) 的情況下,它使用 $LANG 全域變數。

使用 REPL (讀取-求值-輸出迴圈)

echo locale_get_default(); // en_US

然後重設 $LANG

tiikeri@ubuntu:~$ LANG="fi_FI.UTF-8"

回到 REPL

echo locale_get_default(); // fi_FI
To Top