2012-01-29 39 views
0

如何在PHP中使用cURL發佈阿拉伯文字?如何在PHP中使用cURL發佈阿拉伯文文本?

$postData = array(
    'msg' => 'مرحبا' 
); 

curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
+1

什麼不符合您當前的代碼? – Bojangles 2012-01-29 17:39:46

+1

阿拉伯字符 – faressoft 2012-01-29 17:41:06

+0

您的PHP頁面是否編碼爲UTF-8?您是否在HTML中使用了元標記來指示文件是UTF-8? – Hossein 2012-01-29 18:30:49

回答

0

正常應用程序中的CURL POST/x-www-form-urlencoded類。

所以我認爲你需要設置字符集。

你能嘗試用其他選項添加此:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml;charset=utf-8")); 

希望這有助於:)

+0

它不起作用 – faressoft 2012-03-04 03:23:47

0

編碼與urlencode發佈數據...

+0

它不起作用 – faressoft 2012-03-04 03:24:50

0

嘗試設置頁眉和設置選項如下:

$header = array("Content-type:text/xml; charset=utf-8"); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 
curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 

然後你可以發佈你的數據。

最後,不要忘了承諾:

curl_setopt($ch, CURLOPT_POSTFIELDS, "<commit />"); 

(這是從工作方面採取)

0

試試這個,使用GET方法時。

<?php 
//step1 
$cSession = curl_init(); 
//step2 
curl_setopt($cSession,CURLOPT_URL,"http://www.google.com/search?q=curl"); 
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true); 
curl_setopt($cSession,CURLOPT_HEADER, false); 
//step3 
$result=curl_exec($cSession); 
//step4 
curl_close($cSession); 
//step5 
echo $result; 
?>