Google Translate API of PHP GOOGLE翻译PHP 接口
2009-01-19 17:07
447 查看
类:
例子:
[/code]
]<?php class Google_API_translator { public $opts = array("text" => "", "language_pair" => "en|it"); public $out = ""; function __construct() {} function setOpts($opts) { if($opts["text"] != "") $this->opts["text"] = $opts["text"]; if($opts["language_pair"] != "") $this->opts["language_pair"] = $opts["language_pair"]; } function translate() { $this->out = ""; $google_translator_url = "http://google.com/translate_t?langpair="; $google_translator_url .= urlencode($this->opts["language_pair"])."&"; $google_translator_url .= "text=".urlencode($this->opts["text"]); $gphtml = $this->getPage(array("url" => $google_translator_url)); preg_match('/(.*?)</div>/', $gphtml, $out); $this->out = utf8_encode($out[0]); return $this->out; } function getPage($opts) { $html = ""; if($opts["url"] != "") { $ch = curl_init($opts["url"]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $html = curl_exec($ch); if(curl_errno($ch)) { $html = ""; } curl_close ($ch); } return $html; } } ?>
例子:
]<?php $g = new Google_API_translator(); $g->setOpts(array("text" => "ciao", "language_pair" => "it|en")); $g->translate(); echo $g->out; ?>
[/code]
相关文章推荐
- PHP Google的translate API代码
- Google翻译接口(PHP API)
- PHP Google的translate API代码
- PHP查询Google PR值接口API介绍
- 结合Google Maps API和GeoIP/新浪/搜狐接口的IP地理信息可视化查询
- api 接口开发理论 在php中调用接口以及编写接口
- 用PHP实现飞信api接口发飞信短信
- PHP的TokyoTyrant扩展接口API文档(PECL)
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
- php飞信api接口[免费使用]
- 利用Google API Enging做验证码的人工识别接口
- php的api数据接口书写实例
- php、js两种不同方式根据关键词返回经纬度接口【基于Google map API】
- Short List of RESTful API Frameworks for PHP
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
- PHP 与手机 APP 开发(API 接口开发)
- php怎么将数据库封装,然后提供数据接口让其他API什么的访问
- 借助Google Translate API实现网站多国语言翻译功能
- PHP:CURL分别以GET、POST方式请求HTTPS协议接口api