PHP open gzipped XML

后端 未结 3 1372
清歌不尽
清歌不尽 2020-12-09 06:03

I am struggling to read gzipped xml files in php.

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

$xml = new XMLReader();
$xm         


        
3条回答
  •  眼角桃花
    2020-12-09 06:42

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

    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);
    

    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.

提交回复
热议问题