为什么 php 文件编码影响响应数据编码?
Why php file encoding influence response data encoding?
我使简单的 Web 服务器响应 JSON 字符串 PHP。
在我用 Notepad++ 更改了一些 php 文件之前,它一直运行良好。
从我用 Notepad++ 更改一些 php 文件的那一刻起,我的移动客户端就出错了
CompanyName.ProjectName.V1.Client.ApiException: Unexpected character
encountered while parsing value: . Path ", line 0, position 0.`.
我解决了这个问题,首先删除了 php 个文件中的 'UTF-8 BOM(Binary Order Mask)' 个。
但是,据我所知PHP是脚本语言。为什么 PHP 文件编码影响响应数据编码?
在Python中,与PHP相同的脚本语言,文件编码没有问题。
因为我不太了解PHP,我想知道为什么会这样。
PHP 期望脚本符合 Unicode 标准。根据 Unicode 标准,不建议使用 UTF-8 文件的 BOM:
2.6 Encoding Schemes
Use of a BOM is neither required nor recommended for UTF-8, but may be
encountered in contexts where UTF-8 data is converted from other
encoding forms that use a BOM or where the BOM is used as a UTF-8
signature. See the “Byte Order Mark” subsection in Section 16.8,
Specials, for more information.
帽子提示:What's different between UTF-8 and UTF-8 without BOM?
您可能需要考虑使用能够正确处理 PHP 的编辑软件。我喜欢 Atom (https://atom.io/),这是一款免费的开源软件,支持 PHP 和许多其他语言。
我使简单的 Web 服务器响应 JSON 字符串 PHP。
在我用 Notepad++ 更改了一些 php 文件之前,它一直运行良好。
从我用 Notepad++ 更改一些 php 文件的那一刻起,我的移动客户端就出错了
CompanyName.ProjectName.V1.Client.ApiException: Unexpected character encountered while parsing value: . Path ", line 0, position 0.`.
我解决了这个问题,首先删除了 php 个文件中的 'UTF-8 BOM(Binary Order Mask)' 个。
但是,据我所知PHP是脚本语言。为什么 PHP 文件编码影响响应数据编码? 在Python中,与PHP相同的脚本语言,文件编码没有问题。
因为我不太了解PHP,我想知道为什么会这样。
PHP 期望脚本符合 Unicode 标准。根据 Unicode 标准,不建议使用 UTF-8 文件的 BOM:
2.6 Encoding Schemes
Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature. See the “Byte Order Mark” subsection in Section 16.8, Specials, for more information.
帽子提示:What's different between UTF-8 and UTF-8 without BOM?
您可能需要考虑使用能够正确处理 PHP 的编辑软件。我喜欢 Atom (https://atom.io/),这是一款免费的开源软件,支持 PHP 和许多其他语言。