PHP语言环境de_DE返回英语语言环境 [英] PHP locale de_DE is returning English locale

查看:89
本文介绍了PHP语言环境de_DE返回英语语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu系统上使用Apache和php 7.安装德语语言环境并运行locale -a以检查已安装的语言环境后,得到C, C.UTF-8, de_DE, de_DE@euro, de_DE.iso88591, de_DE.iso885915@euro, de_DE.utf8, deutsch, en_US.utf8, german, POSIX.我还使用sudo update-locale更新了语言环境.但是使用php代码

I am using Apache and php 7 on an Ubuntu System. After installing the german locales and running locale -a to check the installed locales, I get C, C.UTF-8, de_DE, de_DE@euro, de_DE.iso88591, de_DE.iso885915@euro, de_DE.utf8, deutsch, en_US.utf8, german, POSIX. I also update the locale using sudo update-locale. However using the php code

setlocale(LC_ALL,'de_DE');
echo date("F", strtotime("2018-10-10"));

它将返回英文"October",而不是德语"Oktober".我不知道该怎么办...我也重新启动了Apache ...但是什么也没发生.

It returns me the English "October", not the German "Oktober". I have no idea what I can do... I also restarted the Apache... but nothing happened.

推荐答案

date()函数不监听语言环境-这将仅以英语返回值.

The date() function doesn't listen to the locales - this will be returning values in English only.

date()文档中,

要用其他语言格式化日期,应使用setlocale()和strftime()函数,而不要使用date().

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

您需要改用strftime().

setlocale(LC_ALL,'de_DE');
echo strftime("%B", strtotime("2018-10-10"));

  • strftime()文档
  • 这篇关于PHP语言环境de_DE返回英语语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆