2010-12-29

PHP API調用BING翻譯

資料來源:http://www.kalvin.cn/study/php-api-call-bing-translation-results.html
<?php echo bingtrans('大家好,欢迎光临我的博客!'); //return: Hello, and welcome to my blog! 
function bingtrans($str ''$in 'zh-CHS'$to 'en'$api 'C2D5477B17DD7DCB1391E6B4D3222F2DB8AFAE7D') { 
    if (empty(
$str)) { 
        return 
false
    }  
    
$url "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" $api "&text=" urlencode($str) . "&from=" $in "&to=" $to
    if (
function_exists('curl_init')) { 
        
$curl curl_init(); 
        
curl_setopt($curlCURLOPT_URL$url); 
        
curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
        
$res curl_exec($curl); 
    } else { 
        
$res = @file_get_contents($url); 
    }  
    
preg_match("~<string([^><]*?)>([\s\S]*?)<\/string>~i"$res$ostr); 
    if (empty(
$ostr[2])) { 
        return 
false
    } else { 
        return 
htmlspecialchars_decode($ostr[2]); 
    }  
}  
?>

jQuery Version 1.4.4 API 中文版

jQuery API 1.4.4中文版下载


網址:http://www.css88.com/jqapi/