/* Google Translate PHP interface
* Official Written 2009-03-28
* http://blog.csdn.net/aprin/
* Note: If the translated 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 = "";//Translated 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
How is the *ie–urlencode encoded?
*text– the text to be translated
*/
$fields = Array (' Hl=zh-cn&rs
http://www.bkjia.com/PHPjc/478828.html www.bkjia.com true http://www.bkjia.com/PHPjc/478828.html techarticle /* Google Translate PHP interface * Official written 2009-03-28 * http://blog.csdn.net/aprin/* Note: If the translated text is UTF-8 encoded, delete the Mb_convert_encoding function. Class Google_ap ...