Hướng dẫn
php triển khai bản dịch của Google
2024-09-22 03:26:52
Tác giả: Mạng đám mây quản trị trang web
// Khối được đánh dấu
//Google Dịch
hàm 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, false);
Curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, sai);
Curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
Curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Curl_setopt($ch, CURLOPT_MAXREDIRS,20);
Curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
Curl_setopt($ch, CURLOPT_URL, $url);
kết quả $=curl_exec($ch);
Curl_close($ch);
$result = json_decode($result);
if(!empty($result)){
foreach($result[0] as $k){
$v[] = $k[0];
}
return implode(" ", $v);
}
}