HTML/PHP 编码,特殊字符在一台服务器上工作,而不在另一台服务器上工作

问题描述:

我在理解为什么一台运行 PHP/Apache 的服务器正确格式化特殊字符而另一台没有.

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

我使用的元标记是;

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

我也试过了;

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

正确运行的服务器;

Apache/2.4.9 (Win64) PHP/5.5.11

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

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.

HTML 元标记仅对编码信号具有次要意义;HTTP Content-Type 标头 优先(如果存在).一台服务器正在设置该标头,另一台没有(或设置了错误的标头).

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

要么在 Apache 中适当地设置默认字符集,要么在 PHP 中自己显式输出该标头:

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');