我正在尝试将执行shell的php中的一个命令的输出转换为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?
function sapi_windows_cp_get()
接受字符串作为参数
$output = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), 65001, $output);