PHP实现DeepL翻译API调用

2025-08-20php开发问题
168

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。
在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以买到DeepL的Pro账号。
function DeepL($value,$auth_key,$target){
	
    $ch = curl_init();
 free vpn 免费vpn   free vpn vpn free  免费vpn curl_setopt($ch, CURLOPT_URL, 'https://api.deepl.com/v1/translate');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,   免费vpn下载       
    "auth_key=".$auth_key."&text=".$value."&target_lang=".$target);
 
    //这玩意很蛋疼,一定要把HTTPS检测关了。不然无法运行的
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  vpn下载   //这玩意很蛋疼,一定要把HTTPS检测关了。不然无法运行的
 
    $headers = array();
    $headers[] = vpn下载 'Content-Type: application/x-www-form-urlencoded';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
       免费vpn下载  echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);
 
    $translatedWords = json_decode($result, vpn free true); // vpn下载 Decode the word
    $result = $translatedWords['translations'][0]['text']; // Search the word
 
  vpn下载   return $result;
}
$vale = '需要翻译的文本';
$auth_key = ''; //这个是自己要有DeepLPro账号才能生成,直接后台那个key就是,贴进来就行
echo DeepL($value,$auth_key,"EN");
The 免费vpn End
英文翻译

相关推荐