date function, how can I display a non-english name of a month
The function date gives us pretty nice features when working with time and dates. Working with this function makes things so easy. But there is one little problem for those who are going to use the function with a language other than English. It took me some time before I could figure out how could I possibly display month names in Bulgarian language. It is actually very easy and it works every language.
The problem is that when you open the documentation, you see a huge list of all available date formats. And then you keep look for the thing that exactly fits your taste (or at least I used to do that). But it looks like that not everything is written in the Internet and sometimes you just need to work it out on you own:
echo date('J', time()); //outputs the current month, by this time March
Hey wait, I want cyrilic? No problem, here you go:
$array = [1 => 'Януари', 2 => 'Февруари', 3 => 'Март', 4 => 'Април', 5 => 'Май', 6 => 'Юни', 7 => 'Юли', 8 => 'Август', 9 => 'Септември', 10 => 'Октомври', 11 => 'Ноември', 12 => 'Декември'];
//php 5.4 supports shorter way to create arrays, fuck yeah!
And now instead of showing the exact month, we should use the n format which will output the number of the month (1 to 12):
echo 'The current month is ' . $array[ date('n', time()) ];
Using the same way you can create an array for the days of the week and have more fun.
