Reputation: 66560
I'm trying to convert the output of one of the commands in PHP that execute shell to utf8 because json_encode returns an empty string.
I've tried to use mb_detect_encoding
to detect encoding and I wanted to use mb_convert_encoding
but mb_detect_encoding
is returning empty string.
I've got output like this:
2016-04-29 10:09 2�216�720 0.8.1.zip
I've also tried this:
sapi_windows_cp_conv(sapi_windows_cp_get(), 65001, $output);
but this return:
sapi_windows_cp_conv(): Wide char conversion failed
Output code page found in this question PHP UTF-8 to Windows command line encoding
Also tried to convert to utf8 before I'm executing dir using:
shell_exec('chcp 65001 && dir');
but I've got the same results, weird � instead of space and empty mb_detect.
How can I convert the output of shell command on windows to UTF8?
Upvotes: 0
Views: 1469
Reputation: 66560
function sapi_windows_cp_get()
accept string as argument
$output = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), 65001, $output);
Upvotes: 2