The URL I was trying to get data from has the following info:
Remote Address:120.138.69.80:80 Request URL:http://ift.tt/1wg9zOm Request Method:GET Status Code:200 OK (from cache) Request Headers Provisional headers are shown Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 User-Agent:Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Response Headers Cache-Control:maxage=1800 Content-Encoding:gzip Content-Type:text/xml;charset=utf-8 Date:Sun, 07 Dec 2014 09:43:13 GMT Expires:Sun, 07 Dec 2014 10:13:13 GMT Pragma:public Via:1.1 VNG-Cache-123:84 (Lusca) X-Cache:MISS from VNG-Cache-123
So I did this:
$url = 'http://ift.tt/1wg9zOm';
$options = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'));
$context = stream_context_create($options);
$contents = file_get_contents($url, false, $context);
echo $contents;
The result was a lot of weird characters like:
����ogvƯ���.��/`7p\����w�d�b� M����dD��b/�X4A�E�@>.�I7h���P�����'��w$��M2LSb.lQ�D����x��<��d�Y����?���������kI0����|�g���'w'˳�"8��ӷ��[۲~��{w���O DZ�X��:��|
I assume the returned data has been gzipped. So I tried using gzdecode API as follows:
echo gzdecode($contents);
And I got:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Much appreciated if any PHP expert can help me further with this.
RC2
No comments:
Post a Comment