PHP setlocale / strftime输出在CLI和Web之间有所不同
我知道有很多关于 PHP 中语言环境的问题。但我找不到任何类似的问题或答案。我需要在网站上输出德语月份名称。已安装德语语言环境。这是 locale -a 的输出:
# locale -a
C
C.UTF-8
POSIX
de_DE
de_DE.iso88591
de_DE.iso885915@euro
de_DE.utf8
de_DE@euro
deutsch
en_US.utf8
german
现在我只使用一个小测试片段:
<?php
echo setlocale(LC_ALL, 'de_DE.utf8')."\n";
echo strftime('%B %Y', strtotime('2022-03-20'))."\n";
这是在命令行上执行它的正确输出:
# php test.php
de_DE.utf8
März 2022
现在,当我在同一服务器上执行相同的片段时Web 浏览器 (file:///x.php) 将加载正确的语言环境,但输出为英语:
de_DE.utf8
March 2022
Apache 2.4.38 用作 Web 服务器。 php cli 版本是 7.2.34,apache 上的 php 模块是 php7_module (shared)
。 php cli 和 php apache 模块之间肯定有区别,但我不知道解决方案?
感谢您的帮助!
I know there are many questions about locale issues in PHP. But I can't find any similar question or answer. I need to output German month names on a website. German locale is installed. Here is the output of locale -a
:
# locale -a
C
C.UTF-8
POSIX
de_DE
de_DE.iso88591
de_DE.iso885915@euro
de_DE.utf8
de_DE@euro
deutsch
en_US.utf8
german
Now I just use a little test snippet:
<?php
echo setlocale(LC_ALL, 'de_DE.utf8')."\n";
echo strftime('%B %Y', strtotime('2022-03-20'))."\n";
Here is the correct output from executing it on the command line:
# php test.php
de_DE.utf8
März 2022
Now when I execute the same snippet on the same server with a web browser (file:///x.php) the correct locale will be loaded, but the output is in English:
de_DE.utf8
March 2022
Apache 2.4.38 is used as the web server. The php cli version is 7.2.34 and the php module on apache is php7_module (shared)
. There must be a difference between the php cli and php apache modules, but I don't know the solution?
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。使用
a2dismod perl
禁用Perl模块后问题得到解决。此后,网站还会显示正确的日期格式。I found the solution. The problem was solved after disabling the Perl module with
a2dismod perl
. After this the website shows also the correct date format.