PHP online translation function code

Source: Internet
Author: User
Tags php online

Code sharing
Copy codeThe Code is as follows:
<?
/**
* GOOGLE translation
*
* @ Param string $ text translation sentence
* @ Return unknown
*/
Function googleTran ($ text ){
If (empty ($ text) return "";
Sleep (1); // opposite Disk
$ Wf = @ file_get_contents ('HTTP: // translate.google.cn/translate_t? Sl = en & tl = zh-CN & text = '. urlencode ($ text ).'#');
If (false ===$ wf | empty ($ wf )){
Return false;
}

// Intercept related information
$ Return = "";
$ Wf = strip_tags ($ wf, "<div> ");
$ Star = strpos ($ wf, "<div id = result_box dir = \" ltr \ "> ");
If (false ===$ star ){
Return false;
}
$ End = strpos ($ wf, "</div> <div id = clir> ");
If (false ===$ end ){
Return false;
}
$ Return = strip_tags (substr ($ wf, $ star, $ end-$ star ));

Return iconv ("GB2312", "UTF-8", trim ($ return ));

}
?>

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.