Home  >  Article  >  Backend Development  >  PHP online translation function code_PHP tutorial

PHP online translation function code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:46:311364browse

Share the code with everyone

Copy the code The code is as follows:

/**
* GOOGLE Translation English-Chinese
*
* @param string $text translation sentence
* @return unknown
*/
function googleTran($text){
if(empty($text)) return "";
sleep(1);//return
$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; 🎜> $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));

}
?>





http://www.bkjia.com/PHPjc/320135.html
www.bkjia.com

true

TechArticleThe code is shared with everyone. Copy the code as follows: ? /*** GOOGLE Translate English-Chinese * * @param string $text translation sentence * @return unknown*/ function googleTran($text) { if(empty($text)) retu...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn