Bluemagica
Bluemagica

Reputation: 5158

How to deal with accented characters in PHP

I am trying to fetch IP details of the user from the following url: http://freegeoip.net/json/186.80.156.123

Now if you open up the above URL, you will see that the city parameter has an weird character in place of an accented character...how can I fix it before displaying in php?

my code

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://freegeoip.net/json/".trim($user->ip_address));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_out = curl_exec($ch);
curl_close($ch); 
$jout = json_decode($curl_out);
echo $jout->city.", ".$jout->region_name.", ".$jout->country_name;

Upvotes: 0

Views: 1264

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324780

It is encoded in UTF-8 but you are interpreting it as ISO-8859-1.

Either set the appropriate options, or just run the $curl_out value through utf8_decode().

Upvotes: 1

Related Questions