我如何使用POST方法进行谷歌翻译

时间:2010-12-04 13:29:02

标签: php zend-framework curl

如何使用POST方法进行Google翻译。我不想出于某种原因使用JS,需要用PHP来做。以下不起作用。

  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; 

  }

1 个答案:

答案 0 :(得分:1)

嘿,伙计,我在google上找到了这个课程。如果这有用,请告诉我:

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