Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

491
Views
How to decode UTF-8 string returned from shell_exec()?

This works:

$csv = " b'\xd0\x9e\xd0\xb4\xd0\xbd\xd0\xb0\xd0\xba\xd0\xbe \xd0\xbe\xd0\xb1\xd0\xb8\xd0\xb4\xd0\xbd\xd0\xbe \xd0\xb1\xd1\x83\xd0\xb4\xd0\xb5\xd1\x82 \xd0\xbf\xd0\xbe\xd1\x82\xd1\x80\xd0\xb0\xd1\x82\xd0\xb8\xd1\x82\xd1\x8c \xd0\xbd\xd0\xb0 \xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0 \xd0\xb2\xd1\x80\xd0\xb5\xd0\xbc\xd1\x8f, \xd0\xba\xd0\xbe\xd1\x82\xd0\xbe\xd1\x80\xd0\xbe\xd0\xb5 \xd0\xbc\xd0\xbe\xd0\xb3\xd0\xbb\xd0\xb8 \xd0\xb1\xd1\x8b \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x81\xd1\x82\xd0\xb8 \xd0\xb1\xd0\xbe\xd0\xbb\xd0\xb5\xd0\xb5 \xd0\xbf\xd0\xbb\xd0\xbe\xd0\xb4\xd0\xbe\xd1\x82\xd0\xb2\xd0\xbe\xd1\x80\xd0\xbd\xd0\xbe.'";
$csv = mb_convert_encoding($csv,'UTF-8');

While this returns unconverted string:

$o = shell_exec('python3.6 /var/www/html/main.py'.'normal');
$contents = mb_convert_encoding($o,'UTF-8');
echo $contents

Python script returns same string. I tried strval() and unpack(), didn't work.
Here is the result of "locale -a": here

Even if i put call to script in eval() it interprets string as data.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try adding this line before calling shell_exec():

putenv('LANG=en_US.UTF-8');
over 4 years ago · Santiago Trujillo Report

0

I put this in php script and i don't have to encode anything between scripts,it just works:

putenv("PYTHONIOENCODING=utf-8");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!