Michael Michael - 1 year ago 146
PHP Question

PHP passthru: unable to get full response from python script

I'm trying to get data from Python script:

import pymorphy2
import json
import sys

morph = pymorphy2.MorphAnalyzer()
butyavka = morph.parse(sys.argv[1])[0]
for item in butyavka.lexeme:

PHP code:

passthru('python WordAnalizator.py "слово"', $out);

If I use console, it make correct response, like:

enter image description here

But in PHP I have only first word:

enter image description here

Whats wrong?

Answer Source

This is obvious encoding problem (Russian letters become unreadable). So, try to set (i.e. change default) encoding in the PHP code, e.g. add to header usage of Unicode:

 header('Content-Type: text/html; charset=utf-8');

If charset=utf-8 does not help, try charset=windows-1251 instead.


Do not forget to save your file (PHP code in UTF encoding for utf-8, or ANSI for windows-1251)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download