1

I'm trying to parse an xml feed using PHP: http://trustbox.trustpilot.com/r/travelnation.co.uk.xml

Visiting this, it looks perfectly OK, but when I try

<?php
$file = file_get_contents("http://trustbox.trustpilot.com/r/netamity.com.xml");
print_r($file);
?>

I get

‹•SÁŽÓ0=/ÿ`ŒÄmœ-  븊àèJV«••L«ŽmÙN²ý{Æi·M
...

How is it getting garbled? Using simplexml it wont parse it (unsurprisingly). I've tried setting headers UTF-8 headers but I think the issue is in the get_file_contents. Any ideas?

4

1 回答 1

1

内容看起来很“奇怪”,仅仅是因为编码被压缩(参见 HTTP 标头Content-Encoding: gzip)。

HTTP/1.1 200 OK
x-amz-id-2: 8wYarFnod0jtLJ3U8ZDN38102fjtG+EbwJjy0tY4YTZncrz9auEcQbzt1vyiSEhq
x-amz-request-id: A60F1E6CA5437776
Date: Sun, 24 Feb 2013 18:00:45 GMT
Content-Encoding: gzip
Last-Modified: Sun, 24 Feb 2013 05:19:11 GMT
ETag: "64eaa6f87768aeb3ae6741ba06318cb6"
Accept-Ranges: bytes
Content-Type: application/xhtml+xml
Content-Length: 52366
Server: AmazonS3

我想您需要知道如何通过 HTTP 读取文件;你可以在 SO 上试试这个

于 2013-02-24T18:09:00.503 回答