【问题标题】:Gibberish when opening remote file with php使用 php 打开远程文件时出现乱码
【发布时间】:2014-06-16 06:42:17
【问题描述】:

我正在努力打开这个 JSON 文件: http://s.trustpilot.com/tpelements/1679763/f.jsonp

我尝试使用 file_get_contents、fread 和 cURL,并尝试使用 utf8_encode、utf8_decode 和 iconv(我的页面编码是 UTF-8)。

问题是当我尝试回显这个字符串时,我得到了完全的胡言乱语: http://i.share.pho.to/340c6074_o.png

如您所见,文件本身应显示标准字符。

有什么想法吗?

谢谢:)

【问题讨论】:

  • 您介意发布失败的完整代码吗?

标签: php curl encoding utf-8 file-get-contents


【解决方案1】:

因为页面被压缩以节省字节,所以您正在胡言乱语。 你可以像这样使用 curl curl --compressed http://s.trustpilot.com/tpelements/1679763/f.jsonp

或者添加参数到 php curl 扩展。 curl_setopt($ch, CURLOPT_ENCODING , "gzip");

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多