首頁  >  文章  >  php教程  >  PHP调用谷歌翻译实现翻译功能

PHP调用谷歌翻译实现翻译功能

WBOY
WBOY原創
2016-06-21 08:51:521367瀏覽

/*
 * PHP调用谷歌翻译
 * author:野草
 * date:2012/3/23
 * email:129@jinzhe.net
 * site:http://yckit.com
 */
function translate($text,$language='zh-cnen'){
 if(empty($text))return false;
 @set_time_limit(0);
 $html = "";
 $ch=curl_init("
http://google.com/translate_t?langpair=".urlencode($language)."&text=".urlencode($text));
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch,CURLOPT_HEADER, 0);
 curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    $html=curl_exec($ch);
    if(curl_errno($ch))$html = "";
 curl_close($ch);
 if(!empty($html)){
  $x=explode("
",$html);
  $x=explode("onmouseout=\"this.style.backgroundColor='#fff'\">",$x[0]);
  return $x[1];
 }else{
  return false;
 }
}
echo translate('개','krzh-cn');



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn