0

I am currently hosting a PHP Facebook app on Heroku, in which I use cURL to obtain data about users from the Graph API.

I am having problems where the data returned contains unicode characters, in that json_decode on the Heroku system isn't outputting the unicode characters correctly. The output on my local system (identical code) is fine.

Looking at the raw JSON returned from Graph, I can see that it contains unicode escapes eg

{"id":"100003517896374","name":"Sky\u00e9     Mont\u00e1na","first_name":"Sky\u00e9","last_name":"Mont\u00e1na","link":"http:\/\/www.facebook.com\/skye.montana.73","username":"skye.montana.73","gender":"female","locale":"en_US"}

On my local system, json_decode converts this to the following object:

stdClass Object ( [id] => 100003517896374 [name] => Skyé Montána [first_name] => Skyé [last_name] => Montána [link] => http://www.facebook.com/skye.montana.73 [username] => skye.montana.73 [gender] => female [locale] => en_US )

On the Heroku system it is converted as follows:

stdClass Object ( [id] => 100003517896374 [name] => Skyé Montána [first_name] => Skyé [last_name] => Montána [link] => http://www.facebook.com/skye.montana.73 [username] => skye.montana.73 [gender] => female [locale] => en_US ) 

My understanding of json_decode is that it will recognise and correctly interpret unicode. In this case, on Heroku, it appears to be recognising unicode, but not interpreting it correctly.

Is there some PHP setting I need to make to fix this? Is it something to do with magic_quotes perhaps? I've set both servers to have the same magic_quotes option (Off) but it makes no difference.

4

1 回答 1

1

好的,像往常一样,在 SO 上发帖 5 分钟后,我找到了答案。

Apache 有一个 AddDefaultCharset 指令。这可以设置为关闭,在响应标头中不添加任何内容;On,其中 iso-8859-1 作为内容类型添加到响应头中;或特定字符集,其中该集作为内容类型添加到响应标头。

在我的本地 Apache 环境中,我使用 AddDefaultCharset 将默认字符集设置为 UTF-8,这将覆盖 HTML 页面的元标记中设置的任何内容。

在 Heroku 上,AddDefaultCharset 设置为关闭,这意味着字符集始终由 HTML 页面中的元标记确定。

我的 EPIC FAIL 是我在元标记中有错字。这在我的本地环境中看不到,因为 Apache 设置优先,但在 Heroku 中可以看到,其中内容类型取决于元标记设置。

于 2012-11-26T14:57:11.053 回答