PHP调用谷歌翻译实现翻译功能
程序员文章站
2024-01-13 22:32:58
...
/*
* PHP调用谷歌翻译
* author:野草
* date:2012/3/23
* email:129@jinzhe.net
* site:http://yckit.com
*/
function translate($text,$language='zh-cnen'){
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("
* PHP调用谷歌翻译
* author:野草
* date:2012/3/23
* email:129@jinzhe.net
* site:http://yckit.com
*/
function translate($text,$language='zh-cnen'){
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("
上一篇: JAVA之二分查找