PHP open gzipped XML

后端 未结 3 1396
清歌不尽
清歌不尽 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:31

    Maybe the function gzdecode could help you : the manual says (quote) :

    Decodes a gzip compressed string

    So, you'd have to :

    • download the XML data
    • get it as a string
    • decompress it with gzdecode
    • work on it with XMLReader

    That would depend on the right extension (zlib I guess) beeing installed on your server, though...

    Mark: Expanding on Pascal's post, here is some example code that should work for you

    $xmlfile = fopen($linkToXmlFile,'rb');
    $compressedXml = fread($xmlfile, filesize($linkToXmlFile));
    fclose($xmlfile);
    $uncompressedXml = gzdecode($compressedXml); 
    
    $xml = new XMLReader();
    $xml->xml($uncompressedXml);
    

提交回复
热议问题