doulilou8560 2018-12-06 00:47
浏览 60

在两个不同的服务器上使用money_format的结果不同

I am using the following code

<?php
$moneyFormat        = '%-#15.2n';
$moneyFormat_none   = '%!-#15.2n';

$locales = array('en_US',
                 'en_EU',
                 'en_GB',
                 'zh_CN',
                 'pl_PL',
                 'ja_JP',
                 'ko_KR',
                 'zh_SG',
                 'zh_TW');
foreach($locales as $key => $value) {
    setlocale(LC_MONETARY, $value);

    echo '<tr>';
        echo '<td align="center">' . $value . '</td>';
        echo '<td align="right">' . money_format($moneyFormat, 12345.67) . '</td>';
        echo '<td align="right">' . money_format($moneyFormat_none, 12345.67) . '</td>';
    echo '</tr>';
};
echo '<tr><td colspan="3"><hr></td></tr>';

setlocale(LC_MONETARY, 'pl_PL.UTF-8');

echo '<tr>';
    echo '<td align="center">pl_PL.UTF-8</td>';
    echo '<td align="right">' . money_format($moneyFormat, 12345.67) . '</td>';
    echo '<td align="right">' . money_format($moneyFormat_none, 12345.67) . '</td>';
echo '</tr>';

setlocale(LC_MONETARY, 'pl_PL.utf8');

echo '<tr>';
    echo '<td align="center">pl_PL.utf8</td>';
    echo '<td align="right">' . money_format($moneyFormat, 12345.67) . '</td>';
    echo '<td align="right">' . money_format($moneyFormat_none, 12345.67) . '</td>';
echo '</tr>';

On my local machine (masOS 10.14.1, PHP 5.6.38) I get the following results: enter image description here

On a different machine (CentOS Linux 7 (Core), PHP 5.6.38) I get: enter image description here

If I run locale -a at the command line I get a list of installed locales...each locale in my array exists in the output from both machines (utf-8 being slightly different).

Looking at the pl_* locales... The macOS machine includes

  • pl_PL.UTF-8
  • pl_PL.ISO8859-2
  • pl_PL

While the Linux machine includes

  • pl_PL
  • pl_PL.iso88592
  • pl_PL.utf8

Why does the output look correct on the macOS machine but not on the Linux machine? Is this something that needs addressed in the PHP.ini file or is it server based? I was under the assumption that, if the locale was listed under locale -a it should work as expected in both places.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
    • ¥15 fluent的在模拟压强时使用希望得到一些建议
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流