这是我正在使用的插件:
add_shortcode( '3', 'execute_python_with_argv3' );
function execute_python_with_argv3() {
$description = array (
array("pipe", "r"), // stdin
array("pipe", "w"), // stdout
);
$application_system = "python ";
$application_path .= plugin_dir_path( __FILE__ );
$application_name .= "3.py";
$separator = " ";
$application = $application_system.$application_path.$application_name.$separator;
$pipes = array();
$proc = proc_open ($application, $description, $pipes);
if (is_resource ( $proc )) {
$response = stream_get_contents ($pipes [1] ); //Reading stdout buffer
}
$final = substr(str_replace("'", "", $response), 1);
echo $final;
echo iconv('UTF-8', 'UTF-8', $final);
}
$response
等于b'\xc4\x8d\xc4\x99\xc4\x97\xc4\x8d\xc4\x8d\xc4\xaf\xc4\x85'
,$final
等于\xc4\x8d\xc4\x99\xc4\x97\xc4\x8d\xc4\x8d\xc4\xaf\xc4\x85
,因此echo iconv('UTF-8','UTF-8',$final);
应该解码并打印čęėččįą
。但它不解码,只打印$final
的字符串,但如果我将$final
打印的字符串粘贴到iconv
的字符串位置,它就能完美地解码。为什么会这样?我该怎么解决这个问题?谢谢。你知道吗
这是我正在使用的Python脚本:
# -*- coding: utf-8 -*-
line="čęėččįą";
enc=line.encode('utf-8')
print (enc);
您需要将环境默认编码设置为
utf-8
。 一种方法是:相关问题 更多 >
编程相关推荐