I like to use set_locale and money_format in my applications for flexibility. You never know when you’re going to go global! I had been using RedHat for a long time, and switched to Debian as I like the distro a lot better. I couldn’t get set_locale to work. Here’s what I was trying, which is almost straight out of the PHP online manual:
<?php setlocale(LC_MONETARY, 'en_US'); echo money_format('%.2n', $amount); ?>
But no joy. I finally figured out that the locales are a bit different in Debian. You can use the ‘locale’ command to show what locales are actually installed on your server:
silver:~# locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= silver:~# locale -a C en_US.utf8 POSIX silver:~#
You can see that the locale on Debian is actually ‘en_US.utf8′. A quick change and my money formatting code was back to it’s old self.
<?php setlocale(LC_MONETARY, 'en_US.utf8'); echo money_format('%.2n', $amount); ?>