php 如何在浏览器中强制使用 UTF-8 编码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7809931/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:24:37  来源:igfitidea点击:

How to force UTF-8 encoding in browser?

phphtmlutf-8character-encoding

提问by mkas

I have page which encoding is declared with

我有声明编码的页面

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

But when I enter the page another encoding (ISO) is chosen in browser. I have tried to set encoding by PHP method

但是当我进入页面时,在浏览器中选择了另一种编码(ISO)。我试图通过 PHP 方法设置编码

header('Content-type: text/html; charset=utf-8');

But it also didn't help. All source files are encoded in UTF-8 without BOM. The only solution which I tried and it had worked was setting encoding in .htaccessfile by adding AddDefaultCharset UTF-8line, but then another pages on the server were not displayed correctly. How can I solve this problem?

但这也没有帮助。所有源文件都以 UTF-8 编码,没有 BOM。我尝试过的唯一解决方案是.htaccess通过添加AddDefaultCharset UTF-8行在文件中设置编码,但是服务器上的另一个页面没有正确显示。我怎么解决这个问题?

采纳答案by Gerben

Disable default charset:

禁用默认字符集:

AddDefaultCharset Off