标题说 UTF-8 但口音没有正确显示 - 为什么?(PHP)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5471902/
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
Header says UTF-8 but accents not showing up properly - why? (php)
提问by JDelage
I abstracted the header from a larger set of php files for clarity. When I load it into Wampserver, the <p>é</p>
appears as ? on the site, despite the header calling for utf-8 charset. What is wrong in this document?
为了清楚起见,我从一组更大的 php 文件中提取了标题。当我将它加载到 Wampserver 时,<p>é</p>
显示为 ? 在网站上,尽管标题要求 utf-8 字符集。这个文件有什么问题?
(Note that I tried to modify the encoding by replacing iso-8859-1 with utf-8, that didn't help.)
(请注意,我尝试通过将 iso-8859-1 替换为 utf-8 来修改编码,但这没有帮助。)
header.php:
头文件.php:
<?php
header('Content-Type:text/html; charset=UTF-8');
echo '<?xml version="1.0" encoding="iso-8859-1"?>'
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Blabla</title>
</head>
<body>
<p>é</p>
</body>
</html>
采纳答案by Pekka
You are sending two contradicting character sets, iso-8859-1
and utf-8
.
您正在发送两个相互矛盾的字符集,iso-8859-1
并且utf-8
.
If you
如果你
fix that and send only one character set, and
encode the actual file in the character set you specify (there should be a character set option in your IDE's or editor's "Save as..." dialog)
解决这个问题,只发送一个字符集,和
以您指定的字符集对实际文件进行编码(IDE 或编辑器的“另存为...”对话框中应该有一个字符集选项)
it should work.
它应该工作。
回答by Headshota
try this<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
in the head section
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
在头部部分试试这个
and also check your file encoding
并检查您的文件编码
回答by Benbiga Badr
this worked for me : I add to the MVC COntroller : produces={"application/json;charset=utf-8"}
这对我有用:我添加到 MVC 控制器:产生={"application/json;charset=utf-8"}