samjsharples Posted September 30, 2014 Share Posted September 30, 2014 (edited) 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��sƒ���-}#v���]K���������HB�$&G�����Y�����'߷s�,�.4֫'?'���9;*9^��>�j~�ǫ}z|hq�J��Գ".o2)~b���U~I| How to a convert it back into XML? Many thanks Edited September 30, 2014 by samjsharples Quote Link to comment https://forums.phpfreaks.com/topic/291373-receiving-compressed-data-and-uncompressing-xml-php-gzip-deflate/ Share on other sites More sharing options...
requinix Posted October 1, 2014 Share Posted October 1, 2014 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); Quote Link to comment https://forums.phpfreaks.com/topic/291373-receiving-compressed-data-and-uncompressing-xml-php-gzip-deflate/#findComment-1492472 Share on other sites More sharing options...
samjsharples Posted October 1, 2014 Author Share Posted October 1, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/291373-receiving-compressed-data-and-uncompressing-xml-php-gzip-deflate/#findComment-1492486 Share on other sites More sharing options...
requinix Posted October 1, 2014 Share Posted October 1, 2014 What's your current code? All of it, please, not just a few lines. Does the timeout happen before the cURL call, during the curl_exec(), or sometime later? Quote Link to comment https://forums.phpfreaks.com/topic/291373-receiving-compressed-data-and-uncompressing-xml-php-gzip-deflate/#findComment-1492488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.