Jump to content

Recommended Posts

I am being sent an XML feed which needs to be downloaded in a 'compressed way'.

The example I have been given is this:

 

$url = 'http://myurl.com';
$headers[] = "Accept-Encoding: gzip,deflate";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$data = curl_exec($ch);

 

but the output I am getting is jargon like this with loads of black diamond question marks:

 

+T-}#v]KHB$&GY'߷s,.4֫'?'9;*9^>j~ǫ}z|hqJԳ".o2)~b​U~I|

 

How to a convert it back into XML?

Many thanks

Edited by samjsharples

First, you need CURLOPT_RETURNTRANSFER. Then $data will be a string and you won't get output immediately. You might already have done this for all I know.

 

There's a lot of manual work you could do to support encoding types. Don't do that.

Instead use CURLOPT_ENCODING: cURL will not only set the Accept-Encoding header for you but automatically decode the content as well.

$url = 'http://myurl.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
$data = curl_exec($ch);

Hi requinix

 

Thanks for your answer. I'm still struggling to use this. How can I use the variable $date once this has been executed? If I use print_r I just get a long page load then a timeout message but the XML isn't even that big? Any clues?

 

Thanks

Sam

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.