PHP调用谷歌翻译实现翻译功能
经常采集的童鞋估计会有用! br / 原文: a href=http://jinzhe.net/content/technology/server/php-curl-google-translate.html rel=nofollowhttp://jinzhe.net/content/technology/server/php-curl-google-translate.html/a
经常采集的童鞋估计会有用!
原文: http://jinzhe.net/content/technology/server/php-curl-google-translate.html
原文: http://jinzhe.net/content/technology/server/php-curl-google-translate.html
<?php
/*
* PHP调用谷歌翻译
* author:野草
* date:2012/3/23
* email:129@jinzhe.net
* site:http://yckit.com
*/
function translate($text,$language='zh-cn|en'){
if(empty($text))return false;
@set_time_limit(0);
$html = "";
$ch=curl_init("http://google.com/translate_t?langpair=".urlencode($language)."&text=".urlencode($text));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$html=curl_exec($ch);
if(curl_errno($ch))$html = "";
curl_close($ch);
if(!empty($html)){
$x=explode("</span></span></div></div>",$html);
$x=explode("onmouseout=\"this.style.backgroundColor='#fff'\">",$x[0]);
return $x[1];
}else{
return false;
}
}
echo translate('개','kr|zh-cn');
- 上一篇:用来解析 .htgroup 文件的 PHP 类
- 下一篇:drupal7
精彩图集
精彩文章






