Unicode转PHP执行 [英] Unicode to PHP exec

查看:70
本文介绍了Unicode转PHP执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用PHP的exec函数调用的Python文件.然后,Python输出一个字符串(显然是Unicode,基于使用isinstance),该字符串由PHP回显.我遇到的问题是,如果我的字符串中包含任何特殊字符(如度数符号),将不会输出.我确定我需要做一些事情来弄乱编码,但是我不确定该怎么做,为什么.

I have a Python file I'm calling with PHP's exec function. Python then outputs a string (apparently Unicode, based on using isinstance), which is echoed by PHP. The problem I'm running into is that if my string has any special characters in it (like the degree symbol), it won't output. I'm sure I need to do something to fiddle with the encoding, but I'm not really sure what to do, and why.

编辑:要了解我如何呼叫exec,请参见以下代码段:

To get an idea of how I am calling exec, please see the following code snippet:

$tables = shell_exec('/s/python-2.6.2/bin/python2.6 getWikitables.py '.$title);

当我自己调用getWikitables.py时,Python会正确输出字符串.

Python properly outputs the string when I call getWikitables.py by itself.

肯定是在Python端,还是在传输结果时.当我对PHP中的返回值运行strlen时,得到0.exec只能接受某种类型的编码吗?

It definitely seems to be something either on the Python end, or in transmitting the results. When I run strlen on the returned values in PHP, I get 0. Can exec only accept a certain type of encoding?

推荐答案

在php上,您可以使用 utf8_decode() 来解决您的问题问题.

On php you can use methods like utf8_encode() or utf8_decode() to solve your problem.

这篇关于Unicode转PHP执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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