php exec(python)返回unicode

2024-09-28 20:15:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个PHP脚本,它用参数调用python脚本,并从python返回几个带有print的字符串。在

如果python返回unicode字符,它们将无法在浏览器中正确显示。
如果PHP通过参数向python发送unicode字符,它就会中断。在

Python代码:

# -*- coding: UTF8 -*-
from lxml import html
hparser = html.HTMLParser(encoding="utf-8")
tree = html.parse(url, hparser)
## stuff here..
a = a_el.text.encode("utf-8")
b = b_el.text.encode("utf-8")
print [a, b]

PHP代码:

^{pr2}$

浏览器中的输出要么给我\xc3\c85一些东西,要么给我一个黑色菱形的问号。
我试过使用utf8_encode($string),但没用。在

我也做了一些研究,但运气不好。
我希望能够从PHP向python发送/接收unicode字符。在


Tags: 字符串代码text脚本参数htmlunicode浏览器