php
  • curl
  • 2012-01-25 2 views 1 likes 
    1

    내 코드는 여기에 다른 문제와 다르다. 문제는 필자가 성공적으로 페이지를 말리기 만하면되지만 문자는 모두 인식 할 수 없다는 것을 알게된다. 예. " Ƶ ̳̣ 2012 棩", 어떻게 그들을 정상적으로 보이게 만드시겠습니까?이 페이지를 말리면서 인식 할 수없는 문자를 해결하는 방법

    $cookie_file = tempnam('./temp','cookie'); 
    $login_url = 'http://bbs.php100.com/login.php'; 
    $post_fields = 'cktime=3600&step=2&pwuser=username&pwpwd=password'; 
    
    $ch = curl_init($login_url); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
    curl_exec($ch); 
    curl_close($ch); 
    
    $url = 'http://bbs.php100.com/index.php';//or specific page 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
    $contents = curl_exec($ch); 
    
    //preg_match("",$contents,$arr); 
    //echo $arr[1]; 
    
    curl_close($ch); 
    
    +0

    이 문자는 어떻게 보입니까? 커맨드 라인에 표시하거나 페이지에 표시 하시겠습니까? 출력하기 전에 텍스트를 어떻게 수정합니까? – Timur

    +0

    이것은 내 모든 코드이며 웹 브라우저 (firefox)에서이 문자를 볼 수 있습니다. – Phoenix

    답변

    1

    페이지 내용을 변수 및 변환 인코딩으로 저장해야합니다.

    $url = 'http://bbs.php100.com/index.php';//or specific page 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    // Note "1"! It is needed for curl_exec() to return contents of the page 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
    $contents = curl_exec($ch); 
    $contents = iconv('gbk','utf8',$contents); 
    echo $contents; 
    

    당신이하지 UTF-8 인코딩을 사용하는 경우, 필요에 따라 iconv의 두 번째 매개 변수를 설정합니다.

    관련 문제