InOrderToLive
InOrderToLive

Reputation: 196

'file_get_contents' The contents are encrypted?

The problem is when i use file_get_contents to get source (HTML) from this site, the result that i receive is NOT a plain html code.

The code i used:

$source = file_get_contents("http://mp3.zing.vn/bai-hat/Dance-With-My-Father-Luther-Vandross/ZWZ9D6FD.html");
echo $source;
// OR print_r($source);

The source i received:

��}{�#Ǒ��-��!E��=��Mv�5�B���R�����h��E�HV7YE�������a�X��p{��[�:�!{��;,v��u��Or��̬��Y��M��ʌ̌�����������F��ޖ����ػ��S� #�~��H�7k�����ʎȦ2���M?�ު&D�����t���$u�O��N���>%(Y����I��Vb�[���VN�=�[�![*�dE*�]3:�ޑ�xiA���Z��g ��祇VejI �R�y�֨�ea��o��s�M/�... *MORE

I tried with cURL, but i also received the same result:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mp3.zing.vn/bai-hat/Dance-With-My-Father-Luther-Vandross/ZWZ9D6FD.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$source = curl_exec($ch);
curl_close($ch);

I think the source i received must have been encrypted, but if i use browser to view source, the source will NOT be encrypted.

Eventually, i dont really know what happened, and how to get the plain source (plain HTML) ?

Upvotes: 3

Views: 1527

Answers (2)

h2ooooooo
h2ooooooo

Reputation: 39542

Take a look at gzdecode (requires the ZLIB PHP module, though - if you don't have it, I'd strongly consider to use JimL's method using cURL).

string gzdecode ( string $data [, int $length ] )

$source = file_get_contents("http://mp3.zing.vn/bai-hat/Dance-With-My-Father-Luther-andross/ZWZ9D6FD.html");
echo gzdecode($source);
// OR print_r($source);

Upvotes: 1

JimL
JimL

Reputation: 2541

It's gzip compressed, just set the correct encoding and you're good to go

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mp3.zing.vn/bai-hat/Dance-With-My-Father-Luther-Vandross/ZWZ9D6FD.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
$source = curl_exec($ch);
curl_close($ch);

Upvotes: 5

Related Questions