乱码的xml输出 [英] garbled xml output
问题描述
我正在尝试使用 PHP 解析 xml 提要:http://trustbox.trustpilot.com/r/travelnation.co.uk.xml
访问这个,它看起来完全没问题,但是当我尝试时
我明白
‹•SÁŽÓ0=/ÿ`ŒÄmœ- 븊àèJV«••L«ŽmÙN²ý{Æi·M...
怎么乱码了?使用 simplexml 它不会解析它(不出所料).我已经尝试将标头设置为 UTF-8 标头,但我认为问题出在 get_file_contents 中.有什么想法吗?
内容看起来很奇怪",只是因为编码被压缩(参见 HTTP 标头 Content-Encoding: gzip
).
HTTP/1.1 200 OKx-amz-id-2:8wYarFnod0jtLJ3U8ZDN38102fjtG+EbwJjy0tY4YTZncrz9auEcQbzt1vyiSEhqx-amz-request-id:A60F1E6CA5437776日期:2013 年 2 月 24 日星期日 18:00:45 GMT内容编码:gzip上次修改时间:2013 年 2 月 24 日星期日 05:19:11 GMTETag:64eaa6f87768aeb3ae6741ba06318cb6"接受范围:字节内容类型:应用程序/xhtml+xml内容长度:52366服务器:AmazonS3
我想您需要知道如何通过 HTTP 读取文件;你可以试试这个在SO上.>
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?
The content looks "weird" simply because the encoding is compressed (see the HTTP header 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
I guess what you need is to know how to read a file over HTTP; you could try this one on SO.
这篇关于乱码的xml输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!