0

I want to make PHP print out these characters out of python: ĄČĘĖĮŠŲŪŽąčęėįšųūž. If text in python program's output has one of these characters then the output is blank(PHP just doesn't echo anything), however, this program prints out data that contains ASCII characters. How do I encode my PHP plugin to echo UTF-8 symbols from python?

This is my python script:

#!/home/meteo/.local/bin/python3
print("ĄČĘĖĮŠŲŪŽąčęėįšųūž")

This is PHP plugin I use:

<?php # -*- coding: utf-8 -*-
/* Plugin Name: viassh */   
header('Content-Type: text/html; charset=utf-8');
add_shortcode('viassh', 'HelloWorldShortcode');
function HelloWorldShortcode() {
ob_start();
$old_path = getcwd(); 
chdir('/home/meteo/public_html/wp-content/plugins/');
$output = shell_exec('./4230.py');
chdir($old_path);
echo $output;
$output = ob_get_clean();
return $output;
}

If I add line like this in php plugin, it gets echoed: echo "ėčįęįšėįž";.

I had problem similar to this on my windows computer and the solution was to find python encoding with:

import sys
print(sys.stdout.encoding)

and add this line to my php plugin header('Content-Type: text/html; charset=utf-8'); charset value must be the same as python encoding. So I have tried this on my VPS, python editor through(the one you start withpython3) ssh said that encoding is UTF-8, but python program that was running through my php plugin said that it's encoding is ANSI_X3.4-1968, I have tried changing charset values with these encodings but python data still didn't get printed, so I am out of ideas.

Also the program with symbols can be run through ssh without any problem.

Thanks for reading, any help would be appreciated.

MakeMeWise
  • 31
  • 1
  • 7
  • Maybe http://stackoverflow.com/questions/13961870/php-exec-change-encoding is helpful – apokryfos Jul 11 '16 at 13:42
  • @apokryfos Thanks for your response, it seems that this post kind of pointed me to the right direction, but I still have some problems. The letters that I am trying to print are Lithuanian, so I set `$locale` to be `lt_LT.utf8` and instead of the answer I want to get, which is `ĄČĘĖĮŠŲŪŽąčęėįšųūž`, I get this thing `ĄČĘĖĮŠŲŪŽąÄęėįšųūž` and if I set locale to `lt_LT.iso885913` I get `ÀÈÆËÁÐØÛÞàèæëáðøûþ`, so what locale should I set to? Or what may I be doing wrong? – MakeMeWise Jul 12 '16 at 12:14
  • @apokryfos nvm, thank you very much apokryfos, it works great! :D – MakeMeWise Jul 12 '16 at 12:21

0 Answers0