如何在php中将Windows Shell exec的输出转换为utf8 [英] How to convert output of windows shell exec in php to utf8

查看:165
本文介绍了如何在php中将Windows Shell exec的输出转换为utf8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将php中执行shell的命令之一的输出转换为utf8,因为json_encode返回空字符串.

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.

我尝试使用 mb_detect_encoding 检测编码,我想使用 mb_convert_encoding ,但是 mb_detect_encoding 返回空字符串.

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.

我有这样的输出:

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到Windows命令行编码

Output code page found in this question PHP UTF-8 to Windows command line encoding

还尝试在使用以下命令执行dir之前转换为utf8:

Also tried to convert to utf8 before I'm executing dir using:

shell_exec('chcp 65001 && dir');

但是我得到了相同的结果,很奇怪-而不是空格和空的mb_detect.

but I've got the same results, weird � instead of space and empty mb_detect.

如何将Windows上的shell命令输出转换为UTF8?

How can I convert output of shell command on windows to UTF8?

推荐答案

函数 sapi_windows_cp_get()接受字符串作为参数

function sapi_windows_cp_get() accept string as argument

$output = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), 65001, $output);

这篇关于如何在php中将Windows Shell exec的输出转换为utf8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆