0

I'm trying to convert output of one of the commands in php that execute shell to utf8 because json_encode is return 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 output of shell command on windows to UTF8?

jcubic
  • 51,975
  • 42
  • 183
  • 323
  • What encoding does the shell use? maybe `echo $LANG` have encoding infos. – Mat Dec 22 '17 at 13:25
  • @Mat it's windows cmd.exe not unix. – jcubic Dec 22 '17 at 13:36
  • Could we get some inputs that are generating that output? Also see [what-encoding-code-page-is-cmd-exe-using](http://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using) – Tzalumen Dec 22 '17 at 19:07
  • @Tzalumen It's output of `dir` and the chcp was something like 47x, I don't have access to that windows machine right now. – jcubic Dec 22 '17 at 19:35

1 Answers1

1

function sapi_windows_cp_get() accept string as argument

$output = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), 65001, $output);
jcubic
  • 51,975
  • 42
  • 183
  • 323