Curl 采集乱码与采集不到 PHP,该怎么处理

WBOY
풀어 주다: 2016-06-13 13:50:30
원래의
1094명이 탐색했습니다.

Curl 采集乱码与采集不到 PHP
PHP程序是用gbk2312编码的:

$url = "http://www.sina.com.cn";//gbk2312编码
//$url = "http://www.163.com";//gbk2312编码
//$url = "http://www.sohu.com";//gbk2312编码
 

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);//返回获取的输出的文本流
  $ret = curl_exec($ch);
  curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  curl_close($ch);
  echo $ret;

?>

在采集sina.com.cn时,是正常的,但是采集163.com时是为空的,采集sohu.com时是丢码的.
这是怎么回事呢?如何解决?有哪位怎么呀?先谢谢了!!!没多少分了,不好意思。

------解决方案--------------------
别的不说,我就是来拿分的.楼主记得给全分

PHP code


$curl=curl_init('http://www.163.com');
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)');
$html=curl_exec($curl);
var_dump($html);


$curl=curl_init('http://www.sohu.com');
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)');
$html=curl_exec($curl);
//$html=strstr($html,' 0) {   
   switch ($method) {   
     case 8:   
       // Currently the only supported compression method:   
       $data = gzinflate($body);   
       break;   
     default:   
       // Unknown compression method   
       return false;   
   }   
  } else {   
   // I'm not sure if zero-byte body content is allowed.   
   // Allow it for now...  Do nothing...   
  }   
  
  // Verifiy decompressed size and CRC32:   
  // NOTE: This may fail with large data sizes depending on how   
  //      PHP's integer limitations affect strlen() since $isize   
  //      may be negative for large sizes.   
  if ($isize != strlen($data) || crc32($data) != $datacrc) {   
   // Bad format!  Length or CRC doesn't match!   
   return false;   
  }   
  return $data;   
} <div class="clear">
                 
              
              
        
            </div>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!