php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65371 strftime() returns insufficient string
Submitted: 2013-08-01 11:42 UTC Modified: 2015-02-01 04:22 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kenji dot uui at gmail dot com Assigned: ab
Status: No Feedback Package: Date/time related
PHP Version: 5.5.1 OS: Windows
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-08-01 11:42 UTC] kenji dot uui at gmail dot com
Description:
------------
strftime() breaks UTF-8 Japanese characters.

It worked fine in PHP 5.4.

Test script:
---------------
<?php
function p($str)
{
  echo $str, '<br>';
  echo strftime($str), '<br>';
  echo bin2hex($str), '<br>';
  echo bin2hex(strftime($str)), '<hr>';
}

setlocale(LC_ALL, 'C');
p('あ');


Expected result:
----------------
あ
あ
e38182
e38182


Actual result:
--------------
あ
ぁE
e38182
e3818145


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-02 13:52 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2014-01-02 13:52 UTC] ab@php.net
Please check with bug #65184, the issue your report looks very similar and is most likely already fixed.

Thanks.
 [2014-01-02 13:53 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2014-01-07 05:21 UTC] kenji dot uui at gmail dot com
I've checked PHP 5.5.6, but not yet fixed. Thanks.

Results:
----------------
あ
ぁE
e38182
e3818145
 [2014-01-09 12:36 UTC] ab@php.net
Ok, sadly I can't reproduce it neither with 5.4 nor with 5.5, got your expected result with CLI and built-in server. There has to be something in your env causing this. Maybe you could try on some other machine, with some other locale, etc? Also note that under apache the locale is not thread safe (as apache under windows is threads based), there it might be possible because of it.

Thanks.
 [2014-01-11 13:39 UTC] kenji dot uui at gmail dot com
-Status: Feedback +Status: Assigned
 [2014-01-11 13:39 UTC] kenji dot uui at gmail dot com
I found Windows system locale affects the result.
I changed it to English(US), then I got expected result.

The problem occurs in Japanese locale.
 [2015-01-22 12:01 UTC] ab@php.net
-Status: Assigned +Status: Feedback
 [2015-01-22 12:01 UTC] ab@php.net
Could you please revisit this? There was a lot of locale fixes recently, you could check 5.5.21 or just some recent 5.5 on windows.php.net .

Thanks.
 [2015-01-22 21:36 UTC] kenji dot uui at gmail dot com
-Status: Feedback +Status: Assigned
 [2015-01-22 21:36 UTC] kenji dot uui at gmail dot com
I tested on PHP 5.5.21. Not fixed yet.

Results:
----------------
あ
ぁE
e38182
e3818145
 [2015-01-22 22:31 UTC] kenji dot uui at gmail dot com
I hear this bug is because of VC11 strftime.

Workround is below:

function strftime_win($str)
{
  $str = mb_convert_encoding($str, 'CP932', 'UTF-8');
  return mb_convert_encoding(strftime($str), 'UTF-8', 'CP932');
}
 [2015-01-23 12:41 UTC] ab@php.net
-Status: Assigned +Status: Feedback
 [2015-01-23 12:41 UTC] ab@php.net
OK, after some testing i can now reproduce this behavior even with english system locale. For that, just use

setlocale(LC_ALL, "japanese");

I've also tested a bit more and it looks that at least codepages 932, 936, 950 affect strftime to be working a different way, at least with vc11. I made a mini build with vc12, so you can test it http://windows.php.net/downloads/snaps/ostc/65371/ (you'll need the 64 bit crt redistributable http://www.microsoft.com/en-US/download/details.aspx?id=40784).

But actually I'm more like don't believe it's about CRT but the strftime and locale itself. It seems to build a special case along with the code pages listed above (and maybe more). Many other locales which set a single byte code page show correct behaviors when passing utf8 strings to strftime. Yet another try could be with using _strftime_l, however it's the same as strftime just needs an explicitly passed locale, so more like a no-go.

Thanks.
 [2015-02-01 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Mon Mar 30 10:03:11 2015 UTC