$url = "http://translate.google.cn/translate_a/single";
function curlData($url, $type = 'GET', $data = array()){
$ch = curl_init();
if(empty($url) || ! $ch) return false;
if(strtoupper($type) == 'POST'){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}else{
$url .= '?' . http_build_query($data);
}
$user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36";
curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-type:html/text;charset=utf-8")); //设置响应头
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$data1['client'] = 'gtx';
$data1['dt'] = 't';
$data1['dj'] = 1;
$data1['ie'] = 'UTF-8';
$data1['sl'] = 'auto';
$data1['tl'] = 'zh-CN';
$data1['q'] = $_GET['q'] ;
$content = curlData($url,'get',$data1);
echo $content;