设置不带字符集的内容类型

时间:2017-09-29 07:49:52

标签: php apache character-encoding http-headers content-type

我正在尝试将标头Content-Type设置为text/html,但未指定字符集。如果我运行以下代码:

header('Content-Type: text/html');
var_dump(headers_list());

我得到以下输出:

['Content-type: text/html;charset=UTF-8']

自动添加charset参数! Content-Type已更改为Content-type。类型为text的任何内容类型都会出现同样的情况。例如,Content-Type: text/foobar变为Content-type: text/foobar;charset=UTF-8

如果我指定任何其他参数,则保留它们。例如,Content-Type: text/foobar; param=value变为Content-type: text/foobar; param=value;charset=UTF-8

如果我指定charset参数,则标题不会更改。例如Content-Type: text/html; charset=ISO-8859-1保留Content-Type: text/html; charset=ISO-8859-1。在这种情况下,标题字段名称也不会从Content-Type更改为Content-type

如果我指定的内容类型的类型不是text,则标题不会更改。例如,Content-Type: foo/bar保持不变。

如果没有charset参数,是否无法指定基于文本的内容类型?我使用的是PHP 7.1.1和Apache 2.4.26。

0 个答案:

没有答案
相关问题