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:
On a different machine (CentOS Linux 7 (Core), PHP 5.6.38) I get:
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.