Browser displays � instead of #180;(浏览器显示 而不是 )
问题描述
我有一个包含以下文本的 PHP 文件:
I have a PHP file which has the following text:
<div class="small_italic">This is what you´ll use</div>
在一台服务器上,它显示为:
On one server, it appears as:
This is what you´ll use
另外一个,如:
This is what you�ll use
为什么会有所不同,我该怎么做才能使其正确显示(作为撇号)?
Why would there be a difference and what can I do to make it appear properly (as an apostrophe)?
请注意(以供将来参考)
我实现了 Gordon/Gumbo 的建议,只是我是在服务器级别而不是应用程序级别实现的.请注意,(a) 我必须重新启动 Apache 服务器,更重要的是,(b) 我必须用正确编码的更正数据替换现有的坏数据".
I implemented Gordon's / Gumbo's suggestion, except I implemented it on a server level rather than the application level. Note that (a) I had to restart the Apache server and more importantly, (b) I had to replace the existing "bad data" with the corrected data in the right encoding.
/etc/php.ini
/etc/php.ini
default_charset = "iso-8859-1"
default_charset = "iso-8859-1"
推荐答案
您必须确保使用正确的字符集提供内容:
You have to make sure the content is served with the proper character set:
发送带有 header 的内容>
<?php header("Content-Type: text/html; charset=[your charset]"); ?>
或 - 如果 HTTP charset 标头不存在 - 插入 元素进入:
or - if the HTTP charset headers don't exist - insert a <META> element into the <head>:
<meta http-equiv="Content-Type" content="text/html; charset=[your charset]" />
正如属性名称所暗示的那样,http-equiv 相当于一个 HTTP 响应标头,如果未设置相应的 HTTP 标头,用户代理应该使用它们.
Like the attribute name suggests, http-equiv is the equivalent of an HTTP response header and user agents should use them in case the corresponding HTTP headers are not set.
就像 Hannes 在问题的评论中已经建议的那样,您可以查看您的网络服务器返回的标头以查看它提供的编码.两台服务器之间可能存在差异.因此,将上面的 [your charset] 部分更改为工作"服务器的部分.
Like Hannes already suggested in the comments to the question, you can look at the headers returned by your webserver to see which encoding it serves. There is likely a discrepancy between the two servers. So change the [your charset] part above to that of the "working" server.
有关原因的更详细解释,请参阅 Gumbo 的回答.
For a more elaborate explanation about the why, see Gumbo's answer.
这篇关于浏览器显示 而不是 ´的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:浏览器显示 而不是 ´
基础教程推荐
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php中的foreach复选框POST 2021-01-01
- php中的PDF导出 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
