Do I need to set ini_set( 'default_charset', 'UTF-8' );?

后端 未结 4 1234
暗喜
暗喜 2020-12-30 09:53

My framework for each pages does the follow:

ini_set(\'mbstring.internal_encoding\',\'UTF-8\');
ini_set(\'mbstring.func_overload\',7);
header(\'Content-Type:         


        
相关标签:
4条回答
  • 2020-12-30 10:27

    default_charset ini setting should work for you. PHP always outputs a character encoding by default in the Content-type: header using this setting

    0 讨论(0)
  • 2020-12-30 10:32

    Please see https://bugs.php.net/bug.php?id=29983 looks to me like some distros still have the problem

    test case

    echo "ini_get('default_charset') ". ini_get('default_charset')."<br>";
    
    if (!ini_set('default_charset', 'utf-8')) {
    echo "could not set default_charset to utf-8<br>";
    }
    
    0 讨论(0)
  • 2020-12-30 10:37

    No, you don't have to.

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

    sets this for every page already

    0 讨论(0)
  • 2020-12-30 10:41

    When it comes to the http-header, you're OK as the other answers explain.

    But: There are some functions that are default charset aware

    From the description of FILTER_SANITIZE_FULL_SPECIAL_CHARS:

    Like htmlspecialchars, this filter is aware of the default_charset and if a sequence of bytes is detected that makes up an invalid character in the current character set then the entire string is rejected resulting in a 0-length string.

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