Forum Moderators: coopster

Message Too Old, No Replies

Convertion of XML document as .gz

         

toplisek

3:50 pm on May 21, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have XML file like: myxml1.gz.
As there is need it will be convert the well-formed XML document in the given file to an object:
$myxml= simplexml_load_file("myxml1.gz");

How to change within one line into XML to be read as
$myxml= simplexml_load_file("myxml1.xml");

Need help.

whitespace

4:31 pm on May 21, 2015 (gmt 0)

10+ Year Member Top Contributors Of The Month



The ".gz" file extension implies it has been gzip encoded, so this needs to be decoded (perhaps with gzdecode() - PHP 5.4) first.

Something like:

$compressedContent = file_get_contents('myxml1.gz');
$xmlContent = gzdecode($compressedContent);
$myXml = simplexml_load_string($xmlContent);


Although you should probably throw some error checking in the mix too.

How to change within one line into XML


Is "one line" a specific requirement? If you squash it all on one line (ie. no error checking) then you aren't necessarily going to know which bit fails in an error state. (?)

toplisek

7:57 pm on May 21, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sure, you are right. Errors are important.