php 调用谷歌翻译
来源:互联网 发布:mac book pro型号大全 编辑:程序博客网 时间:2024/05/29 11:55
/** *Google Translator *请求谷歌翻译 */class translation{ 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; } }}$translate = new translation();echo $translate->translate('remember', 'kr|zh-cn');