为什么大部分的 from localeconv 基本上都是空的?

发布于 2024-09-28 05:54:01 字数 791 浏览 0 评论 0原文

我在 Windows 7 上运行 PHP 5.3.0、Apache 2.2.11,我尝试运行这个:

setlocale(LC_ALL, 'sv_SE.UTF-8');
print_r(localeconv());

得到这个:

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )

)

这是怎么回事?为什么基本上所有的值都是空的或奇怪的?

I'm running PHP 5.3.0, Apache 2.2.11 on Windows 7 and I tried to run this:

setlocale(LC_ALL, 'sv_SE.UTF-8');
print_r(localeconv());

And got this:

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )

)

What is going on here? Why are basically all the values empty or strange?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事↓在人 2024-10-05 05:54:02

显然,Windows 上的语言环境命名不同...叹息...这修复了它:

setlocale(LC_ALL, 'sv_SE.UTF-8', 'sve');

Apparently locales are named differently on Windows... sigh... This fixed it:

setlocale(LC_ALL, 'sv_SE.UTF-8', 'sve');
灼疼热情 2024-10-05 05:54:02

@Svish

嗯,原因是语言环境依赖于平台。
据我所知,Linux 机器使用下划线作为分隔符。
然而,Windows 机器使用破折号作为分隔符。

例如;-

平台    | 按平台选择的首选区域设置

Linux        | sv_SE

Windows     | sv-SE

好的一点是 setlocale() 支持添加后备区域设置

例如;

$locale = 'sv_SE';

// Replace underscores with dashes for the fallback locale.
setlocale(LC_ALL, $locale . '.UTF-8',
 str_replace('_', '-', $locale) . '.UTF-8');
print_r(localeconv());

// Output:

// Array
// (
//     [decimal_point] => ,
//     [thousands_sep] =>  
//     [int_curr_symbol] => SEK
//     [currency_symbol] => kr
//     [mon_decimal_point] => ,
//     [mon_thousands_sep] =>  
//     [positive_sign] =>
//     [negative_sign] => -
//     [int_frac_digits] => 2
//     [frac_digits] => 2
//     [p_cs_precedes] => 0
//     [p_sep_by_space] => 1
//     [n_cs_precedes] => 0
//     [n_sep_by_space] => 1
//     [p_sign_posn] => 1
//     [n_sign_posn] => 1
//     [grouping] => Array
//         (
//             [0] => 3
//         )

//     [mon_grouping] => Array
//         (
//             [0] => 3
//         )

// )

平台将自动选择它喜欢/支持的区域设置。

您可以轻松查看平台首选的区域设置。即欲

/* try different possible locale names for german */
$loc_de = setlocale(LC_ALL,  'de_DE', 'de-DE');
echo "Preferred locale for german on this system is '$loc_de'";

// Output:
// Preferred locale for german on this system is 'de-DE'

了解更多详细信息,请查看:
https://www.php.net/manual/en/function.setlocale。 php

@Svish

Well, the reason is that locales are platform dependent.
From what I've come to notice, Linux machines use an underscore as their separator.
Yet, Windows machines use a dash as their separator.

For example;-

Platform    | Preferred locale chosen by platform

Linux          | sv_SE

Windows     | sv-SE

The good thing is that setlocale() supports adding fallback locales.

For example;

$locale = 'sv_SE';

// Replace underscores with dashes for the fallback locale.
setlocale(LC_ALL, $locale . '.UTF-8',
 str_replace('_', '-', $locale) . '.UTF-8');
print_r(localeconv());

// Output:

// Array
// (
//     [decimal_point] => ,
//     [thousands_sep] =>  
//     [int_curr_symbol] => SEK
//     [currency_symbol] => kr
//     [mon_decimal_point] => ,
//     [mon_thousands_sep] =>  
//     [positive_sign] =>
//     [negative_sign] => -
//     [int_frac_digits] => 2
//     [frac_digits] => 2
//     [p_cs_precedes] => 0
//     [p_sep_by_space] => 1
//     [n_cs_precedes] => 0
//     [n_sep_by_space] => 1
//     [p_sign_posn] => 1
//     [n_sign_posn] => 1
//     [grouping] => Array
//         (
//             [0] => 3
//         )

//     [mon_grouping] => Array
//         (
//             [0] => 3
//         )

// )

The platform will automatically choose the locale it prefers/supports.

You can easily view what locale has been preferred by the platform. i.e

/* try different possible locale names for german */
$loc_de = setlocale(LC_ALL,  'de_DE', 'de-DE');
echo "Preferred locale for german on this system is '$loc_de'";

// Output:
// Preferred locale for german on this system is 'de-DE'

For more details, check out:
https://www.php.net/manual/en/function.setlocale.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文