2

My task was to write a script that would be transferred from the php variable in python script, there is a variable return, and php variable output. But the problem arose when the return value of the variable (Russian text). Php code:

$hello = 'Виктор';

$result = shell_exec('main.py ' . $hello);

echo $result;

Python code:

# -*- coding: utf-8 -*-
import sys

text = sys.argv[1]


print (text)

Both files in utf-8 without BOM. Tried and .htaccess, it did not help. Result:������. Any idea how this can be fixed a? I w7, python 3.5, editor of np ++.

  • I've been struggling with this too for a while. It seems that if I use `# -*- coding: Windows-1251 -*- p = "Виктор" print(p)` with `python 2.x` it prints `Виктор` but with `python 3.x` I get an error `UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-11: ordinal not in range(128)` – Pedro Lobito Oct 06 '15 at 19:11
  • If you find the solution please post it here, I'm sure there's a lot of users with the same problem. – Pedro Lobito Oct 06 '15 at 19:47
  • hopefully this helps .. [Stackoverflow](http://stackoverflow.com/questions/10028925/call-a-program-via-shell-exec-with-utf-8-text-input) – mustafa96m Oct 06 '15 at 20:08

0 Answers0