/* Google Translate PHP interface * Official document 2009-03-28 * http://blog.csdn.net/aprin/ * Note: If the translated text is UTF-8 encoded, the mb_convert_encoding function must be deleted */ class Google_API_translator { public $url = “http://translate.google.com/translate_t”; public $text = “”;//Translation text public $out = “”; //Translation output function setText($text){ $this->text = $text; } function translate() { $this->out = “”; $gphtml = $this->postPage($this->url, $this->text); //Extract translation results $out = substr($gphtml, strpos($gphtml, “ “)); $out = substr($out, 29); $out = substr($out, 0, strpos($out, “ )); $this->out = $out; return $this->out; } function postPage($url, $text) { $html =”; if($url != “” && $text != “”) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* *hl – interface language, useless here. *langpair – src lang to dest lang *ie – What is the encoding method of urlencode? *text – the text to be translated */ $fields = array(‘hl=zh-CN&rs