google在线翻译php代码
来源:互联网 发布:淘宝圈子怎么搜索 编辑:程序博客网 时间:2024/05/20 13:12
网上找到的谷歌 在线翻译代码:
<?php
/* Google翻译PHP接口
/ * 注意:如果翻译文本为UTF-8编码,则要删去mb_convert_encoding函数
*/
class Google_API_translator {
public $url = "http://translate.google.com/translate_t";
public $text = "";//翻译文本
public $out = ""; //翻译输出
public $lang_src = "";//要翻译的语言
public $lang_des = "";//翻译成的语言
function setText($text){
$this->text = $text;
}
function setLang($lang_src,$lang_des){
$this->lang_src = $lang_src;
$this->lang_des = $lang_des;
}
function translate() {
$this->out = "";
$gphtml = $this->postPage($this->url, $this->text,$this->lang_src,$this->lang_des);
$out = substr($gphtml, strpos($gphtml, "<div id=result_box dir=/"ltr/">"));
$out = substr($out, 29);
$out = substr($out, 0, strpos($out, "</div>"));
$this->out = $out;
return $this->out;
}
function postPage($url, $text,$lang_src,$lang_des) {
$html ='';
if($url != "" && $text != ""&&$lang_src != ""&&$lang_des != "") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$fields = array('hl=zh-CN', 'langpair='.$lang_src.'|'.$lang_des, 'ie=UTF-8','text='.urlencode(mb_convert_encoding($text, 'UTF-8', 'GB2312')));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $fields));
$html = curl_exec($ch);
if(curl_errno($ch)) $html = "";
curl_close ($ch);
}
return $html;
}
}
?>
- google在线翻译php代码
- PHP 调用Google在线翻译
- PHP 在线翻译函数代码
- 记录 google 在线翻译api
- google在线翻译一
- google在线翻译二
- google在线翻译二
- Google在线翻译(WinForm版)
- google api调用 实现在线翻译
- google在线翻译软件源代码分享
- PHP一行代码集成雅虎宝贝鱼在线翻译功能 -- JAVAEYE不支持IE8
- 在线翻译
- 在线翻译
- 巧用GOOGLE突破网站限制免费在线翻译
- 对比微软、Yahoo和Google在线翻译
- ASP利用Google实现在线翻译功能
- 最近弄了个PHP在线翻译函数
- php利用谷歌实现自动在线翻译
- MyEclipse svn
- Oracle多表连接与子查询
- POJ 1316 Self Number
- WinCE动态修改启动LOGO
- zlib简单用法
- google在线翻译php代码
- WinCE启动界面的定制
- WAG个人总结
- CCSP
- Linux 线程基本编程——线程函数大全
- Map Reduce – the Free Lunch is not over?
- 两个REST client API
- 018_《Delphi下深入Windows核心编程》
- WinCE5.0的USB Camera流接口驱动开发