如何使用POST方法进行Google翻译

问题描述:

如何使用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

嘿,我在google上找到这门课。让我知道如果这是有帮助的:

http://code.google.com/p/gtranslate-api-php/