函式名稱:Spoofchecker::setAllowedLocales()
適用版本:PHP 7.4.0 及以上
函式描述:Spoofchecker::setAllowedLocales() 方法用於設定允許使用的區域設定(locales),以用於 Spoofchecker 類的例項。
語法:public static Spoofchecker::setAllowedLocales(array $locales): bool
引數:
- $locales:一個包含區域設定(locales)字串的陣列。這些區域設定將被設定為允許使用。
返回值:成功時返回 true,失敗時返回 false。
示例:
// 設定允許使用的區域設定
Spoofchecker::setAllowedLocales(['en_US', 'fr_FR', 'es_ES']);
// 建立 Spoofchecker 物件
$spoofchecker = new Spoofchecker();
// 獲取當前設定的允許使用的區域設定
$allowedLocales = $spoofchecker->getAllowedLocales();
// 輸出結果
var_dump($allowedLocales);
輸出:
array(3) {
[0]=>
string(5) "en_US"
[1]=>
string(5) "fr_FR"
[2]=>
string(5) "es_ES"
}
在上面的示例中,我們首先使用 Spoofchecker::setAllowedLocales() 方法設定允許使用的區域設定為英語(en_US)、法語(fr_FR)和西班牙語(es_ES)。然後,我們建立了 Spoofchecker 的例項,並使用 getAllowedLocales() 方法獲取當前設定的允許使用的區域設定。最後,我們將結果輸出到螢幕上,可以看到成功設定了允許使用的區域設定為英語、法語和西班牙語。