PHP calls Google Translator features

Source: Internet
Author: User

PHP calls Google Translator features

From Chinese to English

classGoogle_api_translator { Public $out= ""; functiontranslate () {$this->out = ""; $text=UrlEncode("Computer");//the words to translate        $google _translator_url= "http://translate.google.com/translate_a/t?client=t&text=".$text." &sl=zh_cn&tl=en "; Echo $google _translator_url; $gphtml=$this->postpage (Array("url" =$google _translator_url)); $this->out =$gphtml; return $this-Out ; }    functionPostpage ($opts) {        $html= ""; if($opts["url"]! = "") {            $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$opts["url"]); $html= Curl_exec ($ch); if(Curl_errno ($ch))$html= ""; Curl_close ($ch); }        return $html; }}$g=Newgoogle_api_translator ();$g->translate ();


From English to Chinese

classGoogle_api_translator { Public $out= ""; functiontranslate () {$this->out = ""; $text=UrlEncode("Computer");//the words to translate        $google _translator_url= "http://translate.google.com/translate_a/t?client=t&text=".$text." &SL=EN&TL=ZH_CN "; //Patchwork API URLs for Google Translate        $gphtml=$this->postpage (Array("url" =$google _translator_url)); $this->out =$gphtml; return $this-Out ; }    functionPostpage ($opts) {        $html= ""; if($opts["url"]! = "") {            $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$opts["url"]); $html= Curl_exec ($ch); if(Curl_errno ($ch))$html= ""; Curl_close ($ch); }        return $html; }}$g=Newgoogle_api_translator ();$g->translate ();

is perfect, there are no coding problems in the returned results. The Chinese encoding returned from Google is completely correct.

PHP calls Google Translator features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.