简体   繁体   中英

How to handle this PHP encoding issue?

I'm using PHP to grab some JSON from this URL - goo.gl/xdIqEy

I've tried using cURL and file_get_contents() , but the 'LastName' element always comes back looking like ─Éur─æi─ç

If I view that URL in Chrome, it looks like ÄurÄ'ić

It should look like Đ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.

I've tried a lot of different iconv combinations when I've got the string back in PHP - but no luck.

If I go to that URL in IE, it let's me download the .json file to disk. When I open that in Sublime Text, it looks correct.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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