PHP调用谷歌翻译实现翻译功能
作者:请让我来打酱油 | 来源:互联网 | 2013-04-22 17:17
<?php/**PHP调用谷歌翻译*author:野草*date:2012/3/23*email:129@jinzhe.net*site:http://yckit.com*/functiontranslate($text,$language='zh-cn|en'){if
/*
* PHP调用谷歌翻译
* author:野草
* date:2012/3/23
* email:129@jinzhe.net
* site:http://yckit.com
*/
function translate($text,$language=&#39;zh-cn|en&#39;){
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("
$x=explode("Onmouseout=\"this.style.backgroundColor=&#39;#fff&#39;\">",$x[0]);
echo translate(&#39;&#44060;&#39;,&#39;kr|zh-cn&#39;);