Mike
Mike

Reputation: 105

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?

Upvotes: 0

Views: 153

Answers (1)

Jason OOO
Jason OOO

Reputation: 3552

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

Upvotes: 1

Related Questions