刚接触php,地地道道的菜鸟一个,请教各位高手,我用下边的代码一运行结果是一堆乱码<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 2</title>
</head><body>
<?php
header("Content-Type:text/html;charset=gb2312");$handle = fopen("http://www.dytt8.net/html/gndy/jddy/20131031/43528.html", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
//echo iconv('GB2312', 'UTF-8', $contents);
echo $contents;
?> 
</body></html>
请各位高手帮帮忙

解决方案 »

  1.   

    你读到的数据是 gzip 压缩的,需要解码
    php5.4 已经提供了解码函数 redeclare
    echo $contents;
    改为
    echo gzdecode($contents);
    就可以了如果你的 php 版本较低,那就需要自己书写 gzdecode 函数了
    不过这个函数的代码可以在网上找到解码后输出<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <title>2012年惊悚恐怖《黑色摇滚》720p.BD中英双字幕迅雷下载_电影天堂</title>
    <meta name=keywords content="黑色摇滚下载">
    <meta name=description content="黑色摇滚免费下载,迅雷下载">
    <link href="/css/dygod.css" rel="stylesheet" type="text/css" /><base target="_blank">
    </head><body><div id="header"><div class="contain"><h4><a href="/index.html"></a></h4>
    <div id="headerright"><div id="about" align="right">
                          <SCRIPT src="/gg/760h.js"></SCRIPT>
    </div>
    ..........
      

  2.   

    抓页面什么的还是用python来搞吧,哥们