I need to display to user a list of localized day names (like 'Monday', 'Tuesday', ...) in a form. I know ho to get day name of any date. But is there a particular and fail-proof way to get all day names in an array.
Edit: I could add names of days to my translation file but that is hard to maintain.
Is pretty fail-proof :)
On a more serious note, the likes of PHPBB do this by defining localization files and hard coding for different languages. It's really the only way to do this reliably.
I would recommend downloading something like that and looking at the code to see how its done.
http://www.phpbb.com/downloads/olympus.php
I know its been a long time, but what about:
from how to create array of a week days name in php
This code will work pretty well:-
Now for example you wants to get the any day from array:-
Using
strftime()
in combination withsetlocale()
is an option.However you should be aware that on threaded php installs,
setlocale()
can behave unexpected, since locale information is maintained per process, not per thread. Therefor it is important to callsetlocale()
every time before each call tostrftime()
to guarantee it uses the correct locale.Also, for Windows systems, you need to use somewhat unusual strings for the
$locale
parameter forsetlocale()
.See the docs for more information on both of these issues.
Something like this should work:
Obviously can be optimised by not calling time() 7 times etc but that's the gist. It gives you the right language for the locale and keeps Sun-Sat order of the array in tact.