PHP exec change encoding

后端 未结 3 1640
花落未央
花落未央 2020-12-14 18:46

I need to address UTF-8 filenames with the php exec command. The problem is that the php exec command does not seem to understand utf-8. I use something like th

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 19:27

    To answer my own question - i found the following solution:

    setting the locale environment variable with PHP

    $locale='de_DE.UTF-8';
    setlocale(LC_ALL,$locale);
    putenv('LC_ALL='.$locale);
    echo exec('locale charmap');
    

    This sets to / returns UTF-8. So i'm able to pass special characters and umlauts to linux shell commands.

提交回复
热议问题