ANTICHAT

ANTICHAT (https://forum.antichat.io/index.php)
-   PHP (https://forum.antichat.io/forumdisplay.php?f=37)
-   -   Проблема с curl (https://forum.antichat.io/showthread.php?t=211107)

LASS0 12.06.2010 21:16

Проблема с curl
 
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"); 


wildshaman 12.06.2010 21:23

PHP код:

 $result = curl("http://site.ru/post.php", "text=".urlencode("текст")); 


LASS0 12.06.2010 21:33

получилось :) только сначала из windows-1251 в utf-8
$text = iconv("windows-1251", "utf-8", $text);
$text = urlencode($text);

Kusto 12.06.2010 22:27

Вопрос не стоил отдельной темы, ну а по сабжу примерно так делаю (не проверял)

PHP код:

$res = iconv("utf-8", "windows-1251", curl("http://site.ru/post.php", "text=".urlencode(iconv("windows-1251", "utf-8",$text)))); 



Время: 13:49