HTML/PHP 编码,特殊字符在一台服务器上工作,而不在另一台服务器上工作 [英] HTML/PHP encoding, special characters work on one server for not another

查看:31
本文介绍了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');

这篇关于HTML/PHP 编码,特殊字符在一台服务器上工作,而不在另一台服务器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆