Search code examples
phpwindowsunicodestrftimesetlocale

Unicode setlocale and strftime fails at windows


I have one page and it's encoding is UTF-8 and If i try to run that code in unix system everythings looks fine but when i try to run in windows(7) some chracters looks question mark(�). How can run the code fine both of two system(without using iconv).

header('Content-Type: text/html; charset=UTF-8');
setlocale(LC_ALL, 'turkish');
echo strftime("%d %B %Y, %H:%M");

Solution

  • For those who is having similar problems on linux (this may work also for windows but not sure).

    Yes there is 'turkish' but there is also 'tr_TR.utf8' . If you use 'tr_TR.utf8' most probably your problems will be washed away. Same thing applies also to 'greek'. Instead use 'el_GR.utf8'

    On linux you can check the locale list to find the proper settings for your site.

    locale -a
    

    List is too long and you can't see all languages, so either you can just dump it into a file and then open the file to check.

    locale -a > locale.txt
    vi locale.txt
    

    or do locale -a | grep languagecode for a specific language

    locale -a | grep tr