php 在线翻译 我想做个翻译网站程序我用的是GoogleTranslate.class.php类老显示空白有人有网站翻译的经验吗? 赐教一下 T T 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考http://blog.csdn.net/aprin/archive/2009/03/28/4031371.aspx 我们也做过,不过不是用他的那个类,我们直接发送url得到翻译结果,你用firebug看看你发送出去的请求返回的是什么 那个类是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汗!!!!!!!!!!! <?phpclass 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;?> 还有就是http://translate.google.com/translate?hl=ko&sl=auto&tl=ko&u=http://www.baidu.com这个链接能用浏览器打开我用file_get_contents就显示不了用curl的话得怎么写代码呢? google 有api http://code.google.com/intl/zh-CN/apis/language/#Examples file_get_contents("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en|zh-CN"); $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; 现在想做的效果是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得怎么做的给个思路啊。。! 跨域SESSION问题 PHP的错误抛出机制是什么. 求助。。。。。。。。 经过各位指点,偶重新设计的网上报名系统数据库结构,大虾们再看看哈 问一个关于数据库的问题 问个关于mssql取得查询结果长度被截的问题 恼火呀,正常时间2-3个星期的活要我用两个星期的晚上时间加班完成. 请问那里可以下载 win2000 server/IIS 的安装版本的php,,急,(在线等待) php在线文件编辑 关于php请求头的问题 求解 php session和post 缓存,如何防止回退 php.ini里没有;extension=php_gd.dll,怎么加载GD库函数
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
汗!!!!!!!!!!!
<?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;
?>
http://translate.google.com/translate?hl=ko&sl=auto&tl=ko&u=http://www.baidu.com
这个链接能用浏览器打开
我用file_get_contents就显示不了
用curl的话得怎么写代码呢?
$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;
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
得怎么做的给个思路啊。。!