【问题标题】:PHP: why am I not viewing correctly the text?PHP:为什么我不能正确查看文本?
【发布时间】:2013-08-16 14:46:45
【问题描述】:

我将 PHP 5 和 Apache 都设置为使用 UTF-8 编码。 我试图在我的浏览器中显示这个 PHP 代码的结果:

echo "Trying to visualize the letter ü"

它向我展示了这个结果:

Trying to visualize the letter �

为什么?

【问题讨论】:

  • 您的文件是 UTF-8(没有 BOM)吗?你的 Content-Type 也是 UTF-8 吗?
  • 可能必须显示您在哪里进行了配置更改。在我看来,您只是没有正确设置它
  • @Glavić 我怎么看出来的?反正我是用记事本写的(win 8)
  • @ಠ_ಠ 我在 php conf 文件中添加了 "default_charset = "utf-8";"并在 apache conf 文件“AddDefaultCharset UTF-8”
  • 试试这个<?php header('Content-Type: text/plain; charset=utf-8'); echo "Trying to visualize the letter ü";

标签: php encoding


【解决方案1】:

试试这个:

<?php
header('Content-Type: text/plain; charset=utf-8');
echo "Trying to visualize the letter ü";

如果这不起作用,则说明您的文件与 utf-8 的编码不同。

What's different between UTF-8 and UTF-8 without BOM?

Change File Encoding to utf-8 via vim in a script

【讨论】:

  • 非常感谢。我通过将文件保存为 UTF-8(默认为 ANSI)来解决。我做了“文件->另存为..->编码:UTF-8”。
【解决方案2】:

确保您将文档设置为“Content-Type”http 标头,并将字符集设置为您正在使用的编码:

header("Content-Type: text/html; charset=utf-8");

【讨论】:

    猜你喜欢
    • 2014-12-26
    • 1970-01-01
    • 2022-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2020-02-13
    相关资源
    最近更新 更多