php利用谷歌实现自动在线翻译
来源:互联网 发布:酷狗音频编辑软件 编辑:程序博客网 时间:2024/06/05 06:41
php利用谷歌实现自动翻译,以下是两种实现的方式,php文档用utf8就不会出现乱码问题
第一种利用curl:
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('去');
第二种:利用get方式
function googleTran($text){
if(empty($text)) return "";
//反间碟
$wf=@file_get_contents('http://translate.google.cn/translate_t?sl=zh-CN&tl=en&text='.$text.'#');
if (false===$wf||empty($wf)){
return false;
}
//截取相关信息
$return = "";
$star="style.backgroundColor='\#fff'\">";
$end="</span></span></div>";
$p = "#{$star}(.*){$end}#iU";//i表示忽略大小写,U禁止贪婪匹配
if(preg_match_all($p,$wf,$rs))
{ print_r($rs);
return $rs[1][0];}
}
echo googleTran('去');
- php利用谷歌实现自动在线翻译
- ASP利用Google实现在线翻译功能
- 谷歌的在线翻译API
- asp.net利用google实现在线翻译功能(通用类)
- python实现Android strings.xml文件自动在线翻译
- PHP 调用Google在线翻译
- google在线翻译php代码
- PHP 在线翻译函数代码
- 实现在线翻译js文件
- 利用PHP代码实现网页自动判断转向
- 利用PHP代码实现网页自动判断转向
- Win 2003利用PHP实现mysql数据库自动备份教程
- 利用PHP代码实现网页自动判断转向
- 利用WebHook实现PHP自动部署Git代码
- 在线翻译
- 在线翻译
- 关于在线翻译的简单实现
- google api调用 实现在线翻译
- 关于暴力&瞎搞骗分的一些实例
- DNS基础及域名系统架构
- linux awk命令详解
- 【例 2.7】
- 第九周项目六—委派任务
- php利用谷歌实现自动在线翻译
- 【Vector】STL之Vector相关方法积累
- brew无法make python2.7.8
- Python框架、库和软件资源大全
- OpenStack Hacker养成指南
- ActivityManagerService的源代码分析
- Linux netstat命令详解
- SQL语句执行效率及分析(note)
- JNI总结(一)