我想做个翻译网站程序
我用的是GoogleTranslate.class.php类
老显示空白
有人有网站翻译的经验吗? 赐教一下 T T

解决方案 »

  1.   

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

  2.   

    我们也做过,不过不是用他的那个类,我们直接发送url得到翻译结果,你用firebug看看你发送出去的请求返回的是什么
      

  3.   

     那个类是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
    汗!!!!!!!!!!! 
      

  4.   


    <?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;
    ?>
      

  5.   

     还有就是
    http://translate.google.com/translate?hl=ko&sl=auto&tl=ko&u=http://www.baidu.com
    这个链接能用浏览器打开
    我用file_get_contents就显示不了
    用curl的话得怎么写代码呢?
      

  6.   

    google 有api   http://code.google.com/intl/zh-CN/apis/language/#Examples
      

  7.   

    file_get_contents("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en|zh-CN");
      

  8.   

    $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;
      

  9.   

    现在想做的效果是
    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
    得怎么做的给个思路啊。。!