問(wèn)題描述
我有一個(gè)包含以下文本的 PHP 文件:
I have a PHP file which has the following text:
<div class="small_italic">This is what you′ll use</div>
在一臺(tái)服務(wù)器上,它顯示為:
On one server, it appears as:
This is what you′ll use
另外一個(gè),如:
This is what you?ll use
為什么會(huì)有所不同,我該怎么做才能使其正確顯示(作為撇號(hào))?
Why would there be a difference and what can I do to make it appear properly (as an apostrophe)?
請(qǐng)注意(以供將來(lái)參考)
我實(shí)現(xiàn)了 Gordon/Gumbo 的建議,只是我是在服務(wù)器級(jí)別而不是應(yīng)用程序級(jí)別實(shí)現(xiàn)的.請(qǐng)注意,(a) 我必須重新啟動(dòng) Apache 服務(wù)器,更重要的是,(b) 我必須用正確編碼的更正數(shù)據(jù)替換現(xiàn)有的壞數(shù)據(jù)".
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"
推薦答案
您必須確保使用正確的字符集提供內(nèi)容:
You have to make sure the content is served with the proper character set:
發(fā)送帶有 header 的內(nèi)容>
<?php header("Content-Type: text/html; charset=[your charset]"); ?>
或 - 如果 HTTP charset
標(biāo)頭不存在 - 插入 元素進(jìn)入
:
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
相當(dāng)于一個(gè) HTTP 響應(yīng)標(biāo)頭,如果未設(shè)置相應(yīng)的 HTTP 標(biāo)頭,用戶代理應(yīng)該使用它們.
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 在問(wèn)題的評(píng)論中已經(jīng)建議的那樣,您可以查看您的網(wǎng)絡(luò)服務(wù)器返回的標(biāo)頭以查看它提供的編碼.兩臺(tái)服務(wù)器之間可能存在差異.因此,將上面的 [your charset]
部分更改為工作"服務(wù)器的部分.
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.
有關(guān)原因的更詳細(xì)解釋,請(qǐng)參閱 Gumbo 的回答.
For a more elaborate explanation about the why, see Gumbo's answer.
這篇關(guān)于瀏覽器顯示 而不是 ´的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!