Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: Locale::getPrimaryLanguage - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Locale::getPrimaryLanguage

2025-04-28

Locale::getPrimaryLanguage

locale_get_primary_language

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

Locale::getPrimaryLanguage -- locale_get_primary_languageGets the primary language for the input locale

说明

面向对象风格

public static Locale::getPrimaryLanguage(string $locale): ?string

过程化风格

locale_get_primary_language(string $locale): ?string

Gets the primary language for the input locale

参数

locale

The locale to extract the primary language code from

返回值

The language code associated with the language.

locale 的长度超过 INTL_MAX_LOCALE_LEN 时返回 null

示例

示例 #1 locale_get_primary_language() example

<?php
echo locale_get_primary_language('zh-Hant');
?>

示例 #2 OO example

<?php
echo Locale::getPrimaryLanguage('zh-Hant');
?>

以上示例会输出:

zh

参见

添加备注

用户贡献的备注 1 note

up
16
Mahn
9 years ago
The behaviour when a falsy value is passed as the $locale is undocumented, but it appears that it returns the primary language of the default system language. In my case:

Locale::getPrimaryLanguage(null);

Returns 'en'. So make sure to test $locale before passing it to the method.

官方地址:https://www.php.net/manual/en/locale.getprimarylanguage.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3