一位被互联网耽误的文艺青年

有人说,生命是晚霞衬红日,青松立峭壁,万里黄沙落秋雁,三月阳春映白雪,是金刀宝马,是银貂美酒,是皓月清歌的漂泊……

利用GOOGLE免费接口翻译成英文

利用GOOGLE免费接口翻译成英文

public static function translate($word, $en = ‘en’)
{
if( empty($word) ) return ”;
$word = htmlspecialchars($word, ENT_NOQUOTES);
$len = mb_strlen($word, ‘UTF-8’);
$l = 5000; #单次最大翻译内容长度
$url = ‘http://translate.google.cn/translate_a/single?client=gtx&dt=t&ie=UTF-8&oe=UTF-8&sl=auto&tl=’.$en.’&q=’;
$text = ”;
for($i = 0; $i < $len; $i += $l)
{
$fanyi = self::curl([‘url’=>$url.urlencode( mb_substr( $word, $i, $l, “UTF-8″ ) ),’header’=>self::headerInfo(),’cookie’=>”]);
if(!empty($fanyi[‘content’]))
{
$json = json_decode($fanyi[‘content’], true);
if(isset($json[0][0][0]) && !empty($json[0][0][0]))$text .= $json[0][0][0];
}
}
return $text;
}

oldmyth