0

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?

4
  • What encoding does the shell use? maybe echo $LANG have encoding infos. Commented Dec 22, 2017 at 13:25
  • @Mat it's windows cmd.exe not unix. Commented Dec 22, 2017 at 13:36
  • Could we get some inputs that are generating that output? Also see what-encoding-code-page-is-cmd-exe-using Commented Dec 22, 2017 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. Commented Dec 22, 2017 at 19:35

1 Answer 1

2

function sapi_windows_cp_get() accept string as argument

$output = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), 65001, $output);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.