开发者

Encode string data between PHP and Python

What would be the best way or a simple and good way to encode string data in python for later reading in php?

开发者_如何学编程

Failed examples:

1: In Python:

>>> encoded = u'test ö'.encode('utf-8')
'text \xc3\xb6'

In PHP:

>>> $decoded = utf8_decode('test \xc3\xb6');
test \xc3\xb6

???

2: In Python:

>>> encoded = u'test ö'.encode('latin-1')
'test \xf6'

In PHP:

$decoded = ???;


You have to use double quotes to get backslash escape sequences parsed in PHP.

# php -r 'echo utf8_decode("test \xc3\xb6");'
test ö

And using UTF8 is certainly one of the most interoperable ways to pass string data between programming languages / systems / etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜