PHP CURL无法正确处理编码的返回数据 [英] PHP CURL isn't processing encoded return data properly

查看:59
本文介绍了PHP CURL无法正确处理编码的返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些次要的编码问题.我从这里获取json数据字符串(自己尝试):

Im have some minor encoding issues. Im getting a json data string from here (try it yourself):

http://cdn.content.easports.com/fifa/fltOnlineAssets/C74DDF38-0B11-49b0-B199-2E2A11D1CC13/2014/fut/items/web/179899.json

数据中的名称显示如下

Ari Skúlason

我该如何使用正确的编码来获取此数据,以便对其AriSkúlason进行编码?

How can I fetch this data with proper encoding so its Ari Skúlason?

我试图在php中将其切换到utf-8

I tried switching it to utf-8 like this in php

echo mb_convert_encoding($r,'ISO-8859-1','utf-8');

这使我离我越来越近,但它仍然不正确

which got me closer, but its still not right

Ari Sk�lason

我的php curl请求:

my php curl request:

$location = 'http://cdn.content.easports.com/fifa/fltOnlineAssets/C74DDF38-0B11-49b0-  B199-2E2A11D1CC13/2014/fut/items/web/179899.json';
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                                                                                                        
'Accept: application/json'));
$r = curl_exec($ch);
curl_close($ch);
echo mb_detect_encoding($r);
$r = mb_convert_encoding($r,'ISO-8859-1','utf-8');

print_r($r);

推荐答案

CURLOPT_ENCODING设置另一个curl选项,并将其设置为"以确保它不会返回任何垃圾

set another curl option for CURLOPT_ENCODING and set it to "" to ensure it will not return any garbage

   curl_setopt($ch, CURLOPT_ENCODING ,"");

这篇关于PHP CURL无法正确处理编码的返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆