'file_get_contents'内容是否已加密? [英] 'file_get_contents' The contents are encrypted?

查看:66
本文介绍了'file_get_contents'内容是否已加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,当我使用 file_get_contents 从此站点获取源(HTML)时,收到的结果不是纯HTML代码.

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.

我使用的代码:

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

我收到的来源:

��}{�#Ǒ��-��!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

我尝试使用cURL ,但我也收到了相同的结果:

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.

最终,我真的不知道 发生了什么 ,以及 如何获取原始信息 (纯HTML)?

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

推荐答案

它是gzip压缩文件,只需设置正确的编码即可.

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);

这篇关于'file_get_contents'内容是否已加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆