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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With