class fanyi{ public function fahui($res) { $url="http://api.fanyi.baidu.com/api/trans/vip/translate"; $q=urlencode($res); $from="auto"; $to="auto"; $appid="你的appid"; $salt= rand(10000,99999); $mishi="你的密钥"; $sign= md5($appid.$res.$salt.$mishi); $url="http://api.fanyi.baidu.com/api/trans/vip/translate?q=".$q."&from=".$from."&to=".$to."&appid=".$appid."&salt=".$salt."&sign=".$sign; $result= json_decode($this->crul($url)); $r= (array)$result->trans_result; echo "yuan:".$r[0]->src; echo "<br>"; echo "result:".$r[0]->dst; } public function crul($url){ $ch= curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,5); $file_contect=curl_exec($ch); curl_close($ch); file_put_contents("ccc", $file_contect); return $file_contect; } }