【问题标题】:Why does PHP require such an odd way to specify UTF-8? [duplicate]为什么 PHP 需要这种奇怪的方式来指定 UTF-8? [复制]
【发布时间】:2021-05-29 07:36:58
【问题描述】:

重音字符没有在 PHP 中显示,所以我添加了 header('Content-Type: text/html; charset=UTF-8'); 到标题。仍然没有喜悦。但我已经解决了:

<!DOCTYPE html>
<html>
<head>
<?php
header('Content-Type: text/html; charset=UTF-8"');
?>
<meta http-equiv="Content-type" content="text/html" charset=utf-8" / >
</head>
<body>
  Hélène
</body>
</html>

Notice the difference?  Why should a single double quote before the final single quote make all the difference?
If I drop the php making an html file and insert a double quote before utf-8 in the meta tag the way it should be then it doesn't work!
I'm using Chrome Version 88.0.4324.150 (Official Build) (64-bit) - haven't tested with other browsers.

有什么想法吗?

【问题讨论】:

  • 此代码不起作用。已经开始输出内容后,您将无法输出标题。这也不是标题的有效语法。您应该仔细查看您的测试,因为它似乎无效。
  • "为什么在最后的单引号之前的单双引号会产生重大影响?" - 嗯,偶尔两个错误确实会成为一个正确的。然而,仔细考虑恢复了哪个错字是题外话。

标签: php html utf-8


【解决方案1】:

我不明白你的问题,但无论如何,你总是可以使用 HTML5 中的&lt;meta&gt; 标签

<meta charset="utf-8">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多