我的每个页面框架如下:
ini_set('mbstring.internal_encoding','UTF-8');
ini_set('mbstring.func_overload',7);
header('Content-Type: text/html; charset=UTF-8');
Run Code Online (Sandbox Code Playgroud)
我也需要做ini_set( 'default_charset', 'UTF-8' );吗?
不,你不必.
header('Content-Type: text/html; charset=UTF-8');
Run Code Online (Sandbox Code Playgroud)
已为每个页面设置此项
当谈到http-header时,你可以解释其他答案.
但是:有一些函数是默认的charset意识
从FILTER_SANITIZE_FULL_SPECIAL_CHARS的描述:
与htmlspecialchars一样,此过滤器知道default_charset,如果检测到在当前字符集中组成无效字符的字节序列,则拒绝整个字符串,从而产生0长度的字符串.
小智 5
请参阅https://bugs.php.net/bug.php?id=29983在我看来像一些发行版仍然有问题
测试用例
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>";
}
Run Code Online (Sandbox Code Playgroud)