/**
* GOOGLE翻译 英汉
*
* @param string $text 翻译句
* @return string
*/
protected function _googleTran($text,$language="english"){
echo ".";
if($language=="english") return $text;
if(empty($text)) return "";
sleep(1);//反间碟
$wf=@file_get_contents('http://translate.google.cn/translate_t?sl=en&tl=zh-CN&text='.urlencode($text).'#');
if (false===$wf||empty($wf)) return $text;
//截取相关信息
$return = "";
$star=strpos($wf,"TRANSLATED_TEXT='");
$end=strpos($wf,"';INPUT_TOOL_PATH");
if(false===$star || false===$end){
return $text;
}
$return = strip_tags(substr($wf,$star+17,$end-$star-17));
return iconv("GB2312","UTF-8",trim($return));
}
PHP 在线翻译函数代码
最新推荐文章于 2024-07-13 07:41:13 发布