PHP online translation function code

WBOY
Release: 2016-07-29 08:39:53
Original
2516 people have browsed it

Share the code with everyone

Copy the code The code is as follows:


/**
* GOOGLE Translate English-Chinese
*
* @param string $text translation sentence
* @return unknown
*/
function googleTran($text){
if(empty($text)) return "" ;
  sleep(1);//Anti-interval
  $wf=@file_get_contents('http://translate.google.cn/translate_t?sl=en&tl=zh-CN&text='.urlencode($text).'#' ; ;div>");
$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 above introduces the PHP online translation function code, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template