0

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 = ???;

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.