2

I convert a string in PHP to a date variable and need to print it in the local date in Hebrew language. I print the date to the page with date('M'); which results in March, in English, and my desired result is to print it in the local Hebrew language which should result in מרץ.

I know that there is way to create array and translate each name of month and day manually but I'm interested to convert the date variable that I have into $date into the local PHP date in Hebrew language. What will be the best way to do it?

Yossi Aharon
  • 151
  • 1
  • 12

1 Answers1

2

You need to set the locale first:

if (setlocale(LC_ALL, 'he_IL') === false) {
    throw new Exception("Locale not available on this machine.");
}

And then use strftime(), as date() doesn't respect locale settings:

echo strftime('%B');

Also note that your system needs to have the correct locale installed, which you can list via the command line with locale -a.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98