简体   繁体   中英

HTML/PHP encoding, special characters work on one server for not another

I'm having problems understanding why one server running PHP/Apache is formatting special characters properly and another one isn't.

the meta tag i am using is;

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

I have also tried;

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

the server that is correctly is running;

Apache/2.4.9 (Win64) PHP/5.5.11

the one that is incorrectly formatting, and replacing characters with a black diamond with a question mark inside it, is running;

Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3

I'm assuming its a config issue, Where? I don't know. Perhaps its a difference in default behavior. it cant be the code because it is identical on both servers.

The HTML meta tag only has secondary significance for signalling the encoding; the HTTP Content-Type header takes precedence if present. One server is setting that header, the other isn't (or is setting the wrong one).

Either set your default charset appropriately in Apache, or explicitly output that header yourself in PHP:

header('Content-Type: text/html; charset=iso-8859-1');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM