我想做个翻译网站程序
我用的是GoogleTranslate.class.php类
老显示空白
有人有网站翻译的经验吗? 赐教一下 T T
我用的是GoogleTranslate.class.php类
老显示空白
有人有网站翻译的经验吗? 赐教一下 T T
解决方案 »
- 匹配网页内容的网址的正则
- 救急
- 一个疑难杂症,PHP高手门请进。解决立马给分
- 求一个正则表达式
- 菜鸟问题:win2000professional的IIS+PHP5能不能配置?
- 100分,问题又来了
- 1、使支持php3、phtml格式我在php.ini怎么改 2、如何使php忽略与php3版本中不兼容的错误 在php.ini中怎么改
- 问题,关于一个页面连接
- 在jsp的威胁下,php还有生存的空间吗?
- php用oci_connect连接oracle,同样的参数为什么有的时候能连成功,有的时候连不成功?
- 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
得怎么做的给个思路啊。。!