shell_exec, how to make utf8????

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Ok I am doing a app with shell_exec, and it does not work properly in a swedish OS because someone decided to make the output ascii and not utf8.

How would I go about replacing all missing charachters with right characters?

Like if I do:

$output = shell_exec('ping västtrafik.se);
echo $output;

It prints:
v��sttrafik.se

$output = shell_exec($cmd);
$output = utf8_encode($output);
echo $output;

it prints:
vÇÏsttrafik.se

so how would I get it to print
västtrafik.se?
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Thought I would fix it by doing

PHP:
$output = str_ireplace("Ǿ", "å", $output);
$output = str_ireplace("ÇÏ", "ä", $output);
$output = str_ireplace("Çô", "ö", $output);
echo $output;
But no lol...
 

ichwar

Community Advocate
Community Support
Messages
1,454
Reaction score
7
Points
0
no, I've never gotten that to work for me...
 

TheMan177

New Member
Messages
179
Reaction score
0
Points
0
Try this, add it before you use shell_exec.

PHP:
putenv('LANG=en_US.UTF-8');
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
If it's the locale that's messing it up, then what TheMan suggested should fix it. But if that doesn't, there's a couple things I can think of.

This might go without saying, but make sure that the output will be interpreted as UTF-8:

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

If it's still messing up, then provided that the echo command modifies it in the same way, and provided that you can regularly output the hostname with no change, this might work:

PHP:
$host = 'www.västtrafik.se';
$search = substr(shell_exec("echo $host"), 0, -1);
$output = shell_exec("ping $host");
$output = str_ireplace($search, $host, $output);
 
Top