2010-12-04 86 views
0

如何使用POST方法進行Google翻譯。我不想使用JS出於某種原因,需要使用PHP來完成。以下不起作用。如何使用POST方法進行Google翻譯

public static function googleTranslatePost($text = "What are you looking at", $destLang='fr', $srcLang = 'en') 
    { 

    $http_response = ''; 
    $ch = curl_init('http://translate.google.com/translate_t'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,'hl=en&ie=UTF8&text=-->this+is+a+test<--&langpair=en%7Car'); 
    curl_setopt($ch, CURLOPT_POST,true); 
    curl_setopt($ch, CURLOPT_HEADER,false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
    $http_response = curl_exec($ch); 
    return $http_response; 

    } 
+0

發生了什麼或沒有發生? – 2010-12-04 13:29:49

+0

我沒有得到任何答覆,也沒有從PHP中的錯誤。 – YumYumYum 2010-12-04 13:31:08

回答