【问题标题】:accented letters are not displayed correctly on the server, even if the encoding is correct即使编码正确,重音字母也无法在服务器上正确显示
【发布时间】:2011-04-24 21:23:50
【问题描述】:

我用 utf-8 字符集写了一些 html。 在html的头部还有一个

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 

在本地一切正常,但是当我将文件上传到服务器时,我看到了我所有的信件

àèìòù etc

扭曲。

有人知道这怎么可能是问题吗?服务器是否可能强制使用不是 utf-8 的字符集?

非常感谢

【问题讨论】:

    标签: html xhtml utf-8 character-encoding


    【解决方案1】:

    实际上,META 标签并不是正确 UTF-8 编码所需要的全部。您的服务器可能仍会在页面标题中以 Content-Type: text/html; charset=ISO-8859-1 的形式发送页面。

    您可以检查标题,例如使用 Live HTTP Headers Firefox 插件。

    UTF-8 编码有很多秘诀并使其发挥作用,您可能需要查看this page (UTF-8: The Secret of Character Encoding),它解释了您需要了解的所有内容,并就如何解决编码问题为您提供建议。

    回答您的问题:是的,可以强制服务器使用 UTF-8,例如通过像这样使用 PHP headers() 函数:

    header('Content-Type:text/html; charset=UTF-8');

    【讨论】:

    • 非常感谢这个非常有趣的链接!我也在 .htacess 中尝试了这种方法 AddDefaultCharset utf-8 但它不起作用。你的完美! :)
    【解决方案2】:

    尝试使用 utf-8 编码保存实际文件。这对我有用。 我使用 PHPStorm 作为编辑器:File->File Encoding->utf-8

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-04
      • 2016-06-15
      • 2022-01-15
      • 2015-09-01
      • 1970-01-01
      • 2021-09-17
      • 2020-11-23
      • 1970-01-01
      相关资源
      最近更新 更多