php 在线翻译

callmehare 2011-01-15 02:54:29
我想做个翻译网站程序
我用的是GoogleTranslate.class.php类
老显示空白
有人有网站翻译的经验吗? 赐教一下 T T
...全文
424 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
callmehare 2011-01-15
  • 打赏
  • 举报
回复
直接翻译全部网站 把中文翻译成韩文。。
君望永远 2011-01-15
  • 打赏
  • 举报
回复
可以直接调用Web服务的~
lijpwsw 2011-01-15
  • 打赏
  • 举报
回复
你想翻译产品名称吗???
callmehare 2011-01-15
  • 打赏
  • 举报
回复
现在想做的效果是
http://chinabay.co.kr/?action=detail2&lmode=y&u=http%3A%2F%2Flist.mall.taobao.com%2F50023887%2Fg-st-----40-0--50023887-x.htm%3FTBG%3D19616.16208.37
我现在做到
http://115.68.7.14/taobao.php
得怎么做的给个思路啊。。!
lijpwsw 2011-01-15
  • 打赏
  • 举报
回复


$query = "hello";
$from = "en";
$to = "zh-CN";
$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$query&langpair=$from|$to";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
echo $content;

lijpwsw 2011-01-15
  • 打赏
  • 举报
回复
file_get_contents("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en|zh-CN");
ihefe 2011-01-15
  • 打赏
  • 举报
回复
google 有api

http://code.google.com/intl/zh-CN/apis/language/#Examples
callmehare 2011-01-15
  • 打赏
  • 举报
回复
还有就是
http://translate.google.com/translate?hl=ko&sl=auto&tl=ko&u=http://www.baidu.com
这个链接能用浏览器打开
我用file_get_contents就显示不了
用curl的话得怎么写代码呢?
callmehare 2011-01-15
  • 打赏
  • 举报
回复

<?php
class Google_API_translator {
public $url = "http://translate.google.com/translate_t";
public $text = "";
public $out = "";

function setText($text){
$this->text = $text;
}

function translate() {
$this->out = "";

$gphtml = $this->postPage($this->url, $this->text);

$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) {
$html ='';

if($url != "" && $text != "") {
$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=zh-CN|ko', 'ie=UTF-8','text='.urlencode(mb_convert_encoding($text, 'UTF-8', 'euc-kr')));
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;
}
}

//just for test
$g = new Google_API_translator();
$g->setText("사랑해");
$g->translate();
echo $g->out;
?>
callmehare 2011-01-15
  • 打赏
  • 举报
回复
那个类是Snoopy做的 不用那个类了 用这个类
http://blog.csdn.net/aprin/archive/2009/03/28/4031371.aspx
执行结果
5 Jan 2011 07:11:59 GMT Expires: Sat, 15 Jan 2011 07:11:59 GMT Cache-Control: private, max-age=86400 Content-Type: text/html; charset=GB2312 Content-Language: zh-CN Set-Cookie: PREF=ID=c11812a8d420bfed:NW=1:TM=1295075519:LM=1295075519:S=hItl_jbVyJGxWcEf; expires=Mon, 14-Jan-2013 07:11:59 GMT; path=/; domain=.google.com X-Content-Type-Options: nosniff Server: translation X-XSS-Protection: 1; mode=block Transfer-Encoding: chunked
Web Images Videos Maps News Shopping Gmail more ▼Books
汗!!!!!!!!!!!
lijpwsw 2011-01-15
  • 打赏
  • 举报
回复
我们也做过,不过不是用他的那个类,我们直接发送url得到翻译结果,你用firebug看看你发送出去的请求返回的是什么
ihefe 2011-01-15
  • 打赏
  • 举报
回复
参考

http://blog.csdn.net/aprin/archive/2009/03/28/4031371.aspx

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧