Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

php - Browser displays ? instead of ´

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

And on another, as:

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)?


Note to all (for future reference)

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

default_charset = "iso-8859-1"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to make sure the content is served with the proper character set:

Either send the content with a header that includes

<?php header("Content-Type: text/html; charset=[your 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]" />

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.

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.

For a more elaborate explanation about the why, see Gumbo's answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...