PHP打开压缩的XML [英] PHP open gzipped XML

查看:139
本文介绍了PHP打开压缩的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力阅读php中压缩过的xml文件.

I am struggling to read gzipped xml files in php.

我确实使用XMLReader()成功读取了普通的xml文件:

I did succeed in reading normal xml files, using XMLReader() like this:

$xml = new XMLReader();
$xml->open($linkToXmlFile);

但是,当将xml文件压缩后,这不起作用.如何解压缩文件并使用XMLReader读取文件?

However, this does not work when the xml file is gzipped. How can I unzip the file and read it with the XMLReader?

推荐答案

由于您未指定PHP版本,因此我假设您使用的是PHP5.

As you didn't specify a PHP version, I am going to assume you are using PHP5.

我想知道为什么人们不建议使用内置的 PHP压缩流API .

I am wondering why people haven't suggested using the built in PHP compression streams API.

$linkToXmlFile = "compress.zlib:///path/to/xml/file.gz";
$xml = new XMLReader();
$xml->open($linkToXmlFile);

据我所知,在幕后,它将透明地为您解压缩该文件,并允许您像读取普通xml文件一样阅读该文件.现在,这可能是一种轻描淡写的说法.

From what I understand, under the covers, it will transparently decompress the file for you and allow you to read it as if were a plain xml file. Now, that may be a gross understatement.

这篇关于PHP打开压缩的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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