首页 > PHP > php利用exec或shell_exec调用python,返回中文乱码的解

php利用exec或shell_exec调用python,返回中文乱码的解

PHP 2025-02-04
php利用exec或shell_exec调用python,传递中文参数。

$a=exec("python test.py",$str);
echo $str;

在cmd.py文件输出中含有中文,结果显示乱码。
经过一番搜索,终于找到了解决方法:
exec:
exec("python test.py",$str);
foreach($str as $res)
{
    $str = iconv("GBK", "UTF-8", $res);
}
echo $str;

shell_exec:
$res = shell_exec("python test.py");
echo iconv("GBK", "UTF-8", $res);

热门标签: 抓包   螺丝钉   vb   Hyper-V   倒计时   python打包   Reqable   无网络