Output from shell_exec() containing accented charcters getting mangled

前端 未结 1 1985
[愿得一人]
[愿得一人] 2021-01-22 02:36

I\'ve got a command which I\'m running from PHP using shell_exec(). Sometimes the output of the command will contain accented characters.

When run from Bash, the output

相关标签:
1条回答
  • 2021-01-22 02:55

    The solution that worked for me was to run these commands before shell_exec, to make sure that the correct locale was being used:

    $locale = 'en_GB.utf-8';
    setlocale(LC_ALL, $locale);
    putenv('LC_ALL='.$locale);
    

    Presumably you can just change en_GB to whatever your language is. I noticed that the locale string seems to be case sensitive.

    0 讨论(0)
提交回复
热议问题