php
  • curl
  • 2012-01-25 3 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の2番目のパラメータを設定します。

    関連する問題