标头显示 UTF-8,但重音符号未正确显示 - 为什么? (php)
为了清楚起见,我从一组更大的 php 文件中提取了标头。当我将其加载到 Wampserver 中时, é
在网站上显示为 �,尽管标头调用 utf-8 字符集。这份文件有什么问题?
(请注意,我尝试通过将 iso-8859-1 替换为 utf-8 来修改编码,但这没有帮助。)
header.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>
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?
(Note that I tried to modify the encoding by replacing iso-8859-1 with utf-8, that didn't help.)
header.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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 head 部分尝试这个
并检查您的文件编码
try this
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
in the head sectionand also check your file encoding
您正在发送两个相互矛盾的字符集:
iso-8859-1
和utf-8
。如果您
修复该问题并仅发送一种字符集,
使用您指定的字符集对实际文件进行编码(应该有一个字符集选项在 IDE 或编辑器的“另存为...”对话框中)
它应该有效。
You are sending two contradicting character sets,
iso-8859-1
andutf-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)
it should work.
这对我有用:
我添加到 MVC COntroller : Produce={"application/json;charset=utf-8"}
this worked for me :
I add to the MVC COntroller : produces={"application/json;charset=utf-8"}