php利用exec或shell_exec调用python,返回中文乱码的解
PHP 2025-02-04
php利用exec或shell_exec调用python,传递中文参数。
在cmd.py文件输出中含有中文,结果显示乱码。
经过一番搜索,终于找到了解决方法:
exec:
shell_exec:
$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);
上一篇:PHP生成微信小程序二维码