Руководство
php реализует перевод Google
22.09.2024 03:26:52
Автор: Webmaster Cloud Network
// Выделенный блок
//Google Переводчик
функция gtranslate($text,$to='zh-CN'){
$entext = urlencode($text);
$url = 'https://translate.google.cn/translate_a/single?client=gtx&dt=t&ie=UTF-8&oe=UTF-8&sl=auto&tl='.$to.'&q='.$entext;
set_time_limit (0);
$ch = Curl_init();
Curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
Curl_setopt ($ ch, CURLOPT_HEADER, ложь);
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, правда);
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, ложь);
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE);
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, правда);
Curl_setopt ($ ch, CURLOPT_MAXREDIRS, 20);
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 40);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
локон_закрыть ($ ч);
$result = json_decode($result);
если(!пустой($результат)){
foreach($result[0] как $k){
$v[] = $k[0];
}
return implode(" ", $v);
}
}