简体   繁体   English

PHP strftime语言环境在刷新时发生更改

[英]PHP strftime locale changes on refresh

I am using strftime in a project and I have a strange bug with setting the locale and print it out. 我在项目中使用strftime,但在设置区域设置并打印出来时遇到了一个奇怪的错误。 Here the code: 这里的代码:

<?php
date_default_timezone_set('Europe/Berlin');
setlocale(LC_ALL, "de_DE");

echo strftime("%A, den %d. %B %Y um %R", strtotime('2013-11-26 08:33:45'));

?>

The output is the following: 输出如下:

Dienstag, den 26. November 2013 um 08:33 Denstag,den 26.2013年11月um 08:33

which is correct, but if I refresh the page I get the following (in one time out of 20) 这是正确的,但是如果刷新页面,则会得到以下信息(20之内一次)

Tuesday, den 26. November 2013 um 08:33. 星期二,巢穴26。2013年11月um 08:33。

Why is the language changing? 语言为什么会改变? Do you have any idea? 你有什么主意吗?

Update: 更新:

I created a file with the code above. 我使用上面的代码创建了一个文件。 It's working fine. 一切正常。 In my project I am using Code Igniter, there I have the 在我的项目中,我使用的是Code Igniter,

date_default_timezone_set('Europe/Berlin');
setlocale(LC_ALL, "de_DE");

in my main index.php in the root folder. 在我的主index.php的根文件夹中。 And I am echoing this in a view: 我的观点是:

echo strftime("%A, den %d. %B %Y um %R", strtotime('2013-11-26 08:33:45'));

So the problem is with Code Igniter, is there a cache or something that's changing the locale sometimes to english? 因此,问题出在Code Igniter,是否存在缓存或将语言环境有时更改为英语的内容?

PHP suggests that as of 4.3.0, Try all these possible locales PHP建议从4.3.0开始,尝试所有可能的语言环境

setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');

Secondly, 其次,

Note: On Windows, setlocale(LC_ALL, '') sets the locale names from the system's regional/language settings (accessible via Control Panel). 注意:在Windows上,setlocale(LC_ALL,'')从系统的区域/语言设置(可通过“控制面板”访问)中设置区域设置名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM