【发布时间】:2017-12-22 13:14:51
【问题描述】:
我正在尝试将 PHP 中执行 shell 的命令之一的输出转换为 utf8,因为 json_encode 返回一个空字符串。
我尝试使用mb_detect_encoding 来检测编码,我想使用mb_convert_encoding,但mb_detect_encoding 返回的是空字符串。
我有这样的输出:
2016-04-29 10:09 2�216�720 0.8.1.zip
我也试过这个:
sapi_windows_cp_conv(sapi_windows_cp_get(), 65001, $output);
但是这个返回:
sapi_windows_cp_conv(): Wide char conversion failed
在这个问题PHP UTF-8 to Windows command line encoding中找到的输出代码页
在执行 dir 之前还尝试转换为 utf8:
shell_exec('chcp 65001 && dir');
但我得到了相同的结果,很奇怪——而不是空格和空 mb_detect。
如何将windows上shell命令的输出转换为UTF8?
【问题讨论】:
-
shell 使用什么编码?也许
echo $LANG有编码信息。 -
@Mat 是 windows cmd.exe 不是 unix。
-
我们能否得到一些产生该输出的输入?另见what-encoding-code-page-is-cmd-exe-using
-
@Tzalumen 这是
dir的输出,chcp 大约是 47x,我现在无法访问那台 Windows 机器。
标签: php windows shell utf-8 cmd