/* Google Translate PHP Interface
* Official Documents
* Http://blog.csdn.net/aprin/
* Note: if the translation text is UTF-8 encoded, delete the mb_convert_encoding Function
*/
Class Google_API_translator {
Public $ url = "http://translate.google.com/translate_t ";
Public $ text = ""; // translate text
Public $ out = ""; // translation output
Function setText ($ text ){
$ This-> text = $ text;
}
Function translate (){
$ This-> out = "";
$ Gphtml = $ this-> postPage ($ this-> url, $ this-> text );
// Extract the 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, which is useless here.
* Langpair-src lang to dest lang
* How is the ie-urlencode encoded?
* Text-the text to be translated
*/
$ Fields = array ('hl = zh-CN & rs