日期:2012-02-17  浏览次数:20455 次

/* Google翻译PHP接口

 * 官成文 2009-03-28

 * http://blog.csdn.net/aprin/

 * 注意:如果翻译文本为UTF-8编码,则要删去mb_convert_encoding函数

 */

class Google_API_translator {

 public $url = “http://translate.google.com/translate_t”;

public $text = “”;//翻译文本

public $out = “”; //翻译输出

function setText($text){

 $this->text = $text;

 }

function translate() {

 $this->out = “”;

$gphtml = $this->postPage($this->url, $this->text);

//提取翻译结果

$out = substr($gphtml, strpos($gphtml, “

“));

$out = substr($out, 29);