我的编码有问题...
一切都是 UTF-8 配置的,即我的数据库(postgres)和我的 php 文件。
当我执行这个脚本时:
$eleves = $serviceManager->getAll('Eleve');
echo "<pre>";
print_r($eleves);
echo "</pre>";
我明白了:
[0] => Model_Eleve Object
(
[idEleve:Model_Eleve:private] => 28206
[numeroscolaire:Model_Eleve:private] => ABE290999JOËL
[nom:Model_Eleve:private] => Abedinpour
[prenom:Model_Eleve:private] => Joël
[dateNaissance:Model_Eleve:private] => 1999-09-29
[sexe:Model_Eleve:private] => masculin
[statusCourant:Model_Eleve:private] =>
[statusSuivant:Model_Eleve:private] =>
[adresses:Model_Eleve:private] => Array
(
[0] => Model_Adresse Object
(
[idAdresse:Model_Adresse:private] => 6176
[rue:Model_Adresse:private] => La Delèze
[numero:Model_Adresse:private] => 37
[codePostal:Model_Adresse:private] => 1164
[localite:Model_Adresse:private] => Buchillon
[emplacement:Model_Adresse:private] =>
)
)
这里一切正常。但如果我想要 JSON:
$eleves = $serviceManager->getAll('Eleve');
echo "<pre>";
echo json_encode($eleves, JSON_PRETTY_PRINT);
echo "</pre>";
我明白了:
{
"nom": "Abedinpour",
"prenom": "Jo\u00ebl",
"adresse": [
{
"rue": "La Del\u00e8ze",
"numero": "37",
"localite": "Buchillon"
}
],
"classe": [
"7VSG\/1"
]
},
我不知道为什么它适用于数组而不适用于 json_encode...我试图转换 utf8 中的所有内容(使用 htmlentities)但它告诉我他无法转换“ASCII”
当我尝试在终端中使用此命令显示文件的编码时:
file -I myfile.php
它返回这个:
myfile.php: text/x-php; charset=us-ascii
但我无法将其转换为 utf8:
iconv -f us-ascii -t utf-8 myfile.php > myfile2.php
file -I myfile2.php
myfile2.php: text/x-php; charset=us-ascii
在此先感谢您的帮助