简体   繁体   English

如何处理此PHP编码问题?

[英]How to handle this PHP encoding issue?

I'm using PHP to grab some JSON from this URL - goo.gl/xdIqEy 我正在使用PHP从此URL捕获一些JSON-goo.gl/xdIqEy

I've tried using cURL and file_get_contents() , but the 'LastName' element always comes back looking like ─Éur─æi─ç 我已经尝试过使用cURLfile_get_contents() ,但是'LastName'元素总是回来看起来像─Éur─æi─ç

If I view that URL in Chrome, it looks like ÄurÄ'ić 如果我在Chrome浏览器中查看该URL,则它看起来像ÄurÄ'ić

It should look like Đurđić 它看起来应该像Đurđić

It's obviously some kind of encoding issue, but how to I handle this? 显然是某种编码问题,但是我该如何处理呢? The HTTP response headers don't give any clues to the encoding type. HTTP响应标头不提供有关编码类型的任何线索。

I've tried a lot of different iconv combinations when I've got the string back in PHP - but no luck. 当我用PHP重新获得字符串时,我尝试了许多不同的iconv组合-但没有运气。

If I go to that URL in IE, it let's me download the .json file to disk. 如果我在IE中转到该URL,就让我将.json文件下载到磁盘。 When I open that in Sublime Text, it looks correct. 当我在Sublime Text中打开它时,它看起来是正确的。

Any advice? 有什么建议吗?

You can use: 您可以使用:

<?php
header('Content-Type: text/html; charset=utf-8');
echo iconv("utf-8", "latin1", "BosanÄić");//Bosanči
echo iconv("utf-8", "latin1", "JiráÄek"); //Jiráček
?>

Your input charset is UTF-8 you need to convert back to latin1 您的输入字符集为UTF-8,您需要转换回latin1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM