PHP setlocale / strftime输出在CLI和Web之间有所不同

发布于 2025-01-21 03:44:03 字数 749 浏览 1 评论 0原文

我知道有很多关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眸中客 2025-01-28 03:44:03

我找到了解决方案。使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文