php 我需要设置 ini_set( 'default_charset', 'UTF-8' ); 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8229696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do I need to set ini_set( 'default_charset', 'UTF-8' );?
提问by dynamic
My framework for each pages does the follow:
我对每个页面的框架如下:
ini_set('mbstring.internal_encoding','UTF-8');
ini_set('mbstring.func_overload',7);
header('Content-Type: text/html; charset=UTF-8');
Do I need to do a ini_set( 'default_charset', 'UTF-8' );
too?
我也需要做ini_set( 'default_charset', 'UTF-8' );
吗?
采纳答案by Bart Vangeneugden
No, you don't have to.
不,你不必。
header('Content-Type: text/html; charset=UTF-8');
sets this for every page already
已经为每个页面设置了这个
回答by itpastorn
When it comes to the http-header, you're OK as the other answers explain.
当涉及到 http 标头时,您可以像其他答案所解释的那样。
But: There are some functions that are default charset aware
但是:有一些函数可以识别默认字符集
From the description of FILTER_SANITIZE_FULL_SPECIAL_CHARS:
来自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.
与 htmlspecialchars 一样,此过滤器知道 default_charset,如果检测到构成当前字符集中无效字符的字节序列,则拒绝整个字符串,从而导致长度为 0 的字符串。
回答by gmgj
Please see https://bugs.php.net/bug.php?id=29983looks to me like some distros still have the problem
请参阅https://bugs.php.net/bug.php?id=29983在我看来,某些发行版仍然存在问题
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>";
}
回答by PoX
default_charset ini setting should work for you. PHP always outputs a character encoding by default in the Content-type: header using this setting
default_charset ini 设置应该适合您。默认情况下,PHP 总是在 Content-type: 标头中使用此设置输出字符编码