Проблема с curl

Discussion in 'PHP' started by LASS0, 12 Jun 2010.

  1. LASS0

    LASS0 Member

    Joined:
    3 Jan 2009
    Messages:
    0
    Likes Received:
    17
    Reputations:
    1
    PHP:
    function curl($url, $post)
    {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.4) Gecko/2008102920 AdCentriaIM/1.7 Firefox/3.6"); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_POST, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    return 
    $result;
    }; 
    Как можно сделать, чтобы при отправке post запроса
    PHP:
    $result = curl("http://site.ru/post.php", "text=текст");
    текст кодировался и отправлялся в url code
    PHP:
    $result = curl("http://site.ru/post.php", "text=%d1%82%d0%b5%d0%ba%d1%81%d1%82");
     
  2. wildshaman

    wildshaman Elder - Старейшина

    Joined:
    16 Apr 2008
    Messages:
    478
    Likes Received:
    483
    Reputations:
    99
    PHP:
     $result = curl("http://site.ru/post.php", "text=".urlencode("текст"));  
     
    1 person likes this.
  3. LASS0

    LASS0 Member

    Joined:
    3 Jan 2009
    Messages:
    0
    Likes Received:
    17
    Reputations:
    1
    получилось :) только сначала из windows-1251 в utf-8
    $text = iconv("windows-1251", "utf-8", $text);
    $text = urlencode($text);
     
    #3 LASS0, 12 Jun 2010
    Last edited: 12 Jun 2010
  4. Kusto

    Kusto Elder - Старейшина

    Joined:
    4 Feb 2007
    Messages:
    886
    Likes Received:
    678
    Reputations:
    510
    Вопрос не стоил отдельной темы, ну а по сабжу примерно так делаю (не проверял)

    PHP:
    $res = iconv("utf-8", "windows-1251", curl("http://site.ru/post.php", "text=".urlencode(iconv("windows-1251", "utf-8",$text))));
     
    #4 Kusto, 12 Jun 2010
    Last edited: 12 Jun 2010