PHP online translation function code. The code is as follows :? * ** GOOGLE Translate English-Chinese ** @ paramstring $ text translate sentence * @ returnunknown * functiontran Tran ($ text) {if (empty ($ text) retu code to share with you
The 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 ,"
");
$ Star = strpos ($ wf ,"
");
If (false ===$ star ){
Return false;
}
$ End = strpos ($ wf ,"
");
If (false ===$ end ){
Return false;
}
$ Return = strip_tags (substr ($ wf, $ star, $ end-$ star ));
Return iconv ("GB2312", "UTF-8", trim ($ return ));
}
?>
The pipeline code is as follows :? /*** GOOGLE Translate English-Chinese ** @ param string $ text translate sentence * @ return unknown */function googleTran ($ text) {if (empty ($ text )) retu...