Using locale in PHP on OS X

Sep 26, '07 07:30:00AM

Contributed by: abenoni

I was looking around, trying to find out how to get locale to work in PHP on OS X. After some searching, I found the solution and wanted to share this to save you some work. In Linux, one can do this:

setlocale(LC_ALL, 'nb_NO');
echo strftime(" %A %e %B %Y ");
To get it work in PHP on OS X, you must write it like this:
// set date format to Norwegian:
setlocale (LC_TIME, "no_NO.UTF-8");
// output the date
gmstrftime('%A %e %B %Y, %H:%M');
locale is probably not in your profile path, so you have to look in the locale folder to find your language:
$ ls /usr/share/locale
There you can find the languages you can use; some languages have different locale versions. Note that the encoding of the page must correspond to the locale you are using. That is, if you use no_NO.UTF-8, then you must have in your head:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Take a look at some date formatting tips for gmstrftime for more help.

[robg adds: I haven't tested this one.]

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070925014206546