Home > Backend Development > PHP Tutorial > PHP calls Google Translate_PHP tutorial

PHP calls Google Translate_PHP tutorial

WBOY
Release: 2016-07-13 17:50:27
Original
1427 people have browsed it

/*
 * PHP调用谷歌翻译
 * author:cc
 * date:2012/5/4
 */ 
function translate($text,$language='zh-cn|en'){ 
 if(emptyempty($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(!emptyempty($html)){ 
  $x=explode("

",$html); 
  $x=explode("onmouseout="this.style.backgroundColor='#fff'">",$x[0]); 
  return $x[1]; 
 }else{ 
  return false; 
 } 

echo translate('개','kr|zh-cn'); 
?> 


摘自 PainsOnline的专栏

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478259.htmlTechArticle?php /* * PHP调用谷歌翻译 * author:cc * date:2012/5/4 */ function translate($text,$language=zh-cn|en){ if(emptyempty($text))return false; @set_time_limit(0); $html = ; $ch=cur...
source:php.cn
Previous article:Detailed explanation of php small functions_PHP tutorial Next article:A brief discussion on the fourth part of PHP---recursive functions_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template