Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php windows下strftime编码的问题_Php_Encoding_Utf 8_Strftime - Fatal编程技术网

Php windows下strftime编码的问题

Php windows下strftime编码的问题,php,encoding,utf-8,strftime,Php,Encoding,Utf 8,Strftime,我在Windows下使用strftime('%B')时遇到问题。 问题在于,在windows下,此函数返回非utf8编码的字符串(因为windows不支持UTF-8区域设置)。 我在谷歌上搜索了很多关于这个主题的信息,找到了很多建议,建议只使用utf8\u编码(strftime(“%B”),但这并没有帮助。我在utf8\u encode之后得到一个非常奇怪的字符串。 还有另一种解决方案:使用mb\u convert\u编码,例如: $month = strftime('%B'); $month

我在Windows下使用strftime('%B')时遇到问题。 问题在于,在windows下,此函数返回非utf8编码的字符串(因为windows不支持UTF-8区域设置)。 我在谷歌上搜索了很多关于这个主题的信息,找到了很多建议,建议只使用
utf8\u编码(strftime(“%B”)
,但这并没有帮助。我在
utf8\u encode
之后得到一个非常奇怪的字符串。 还有另一种解决方案:使用
mb\u convert\u编码
,例如:

$month = strftime('%B');
$month = mb_convert_encoding($month, 'UTF-8', 'CP1251'); // For Russian locale
它是有效的,但只有当你为一个确切的地区开发时,这才是好的。但我需要一个通用的解决方案。你可以建议:

$month = strftime('%B');
$month = mb_convert_encoding($month, 'UTF-8', mb_detect_encoding($month));
但这不起作用,因为即使
$month
是非utf8,
mb\u detect\u编码($month)
返回“UTF-8”

有人面对过这个问题并找到了解决办法吗?我需要一个通用的解决方案,因为我要向我最喜欢的Laravel框架发出一个pull请求(它有Form::selectMonth()函数,该函数生成一个HTML
select
输入,并以月份为前缀,它非常适合Linux系统,但在本地化的Windows系统下失败)。

试试这个:

setlocale(LC_ALL, '');

echo(iconv('CP1251', 'UTF-8', strftime('%B')));

是的,我曾经遇到过这个问题,但仍然没有找到解决办法。我最终避免了
mb_detect_encoding
,只给出了我希望获得格式化时间的语言的iso,以及一个调用。