Preparing PHP application to use with UTF-8

前端 未结 5 992
渐次进展
渐次进展 2020-12-05 03:28

UTF-8 is de facto standard for web applications now, but PHP this is not a default encoding for PHP (until 6.0). Most of the server is set up for the ISO-8859-1 encoding by

5条回答
  •  悲&欢浪女
    2020-12-05 04:12

    Basically I do three things to work correctly with czech language:

    1) define locale in PHP:

    setlocale(LC_COLLATE, "cs_CZ");
    setlocale(LC_CTYPE, "cs_CZ");
    

    so you would use something like:

    setlocale(LC_ALL, "en_US.utf8");
    setlocale(LC_ALL, "nl_NL.utf8");
    

    based on language which is currently switched to.

    2) define charset for the database:

    mysql_query("set names latin2 collate latin2_czech_cs");
    

    3) define the charset of PHP/HTML code:

    
    

    I don't use any .htaccess setting. You can modify this for your case, in locale use something like en_US.utf8 (based on language currently which is currently switched to), in charset use utf-8 instead of latin2/iso-8859-2 and it should work well.

提交回复
热议问题