<?php 
/* 
 * PHP调用谷歌翻译BT 微度网络-网络技术中心  yun.widuu.com 
 */ 
function translate($text,$language='zh-cn|en'){ 
 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("</span></span></div></div>",$html); 
  $x=explode("onmouseout=\"this.style.backgroundColor='#fff'\">",$x[0]); 
  return $x[1]; 
 }else{ 
  return false; 
 } 
} 
echo translate('微度网络','kr|zh-en');
如果我们把这些再修改一下就可以添加到网站中,这样我们的网站就可以做中英文翻译,欢迎转载,转载请注明来自微度网络-网络技术中心
http://yun.widuu.com                        
                        
                     
                    
                    
发表评论 取消回复