File: /www/wwwroot/www.baofufacai.com///fy/index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>赛脑--翻译中心</title>
</head>
<body>
<?php
// 定义翻译源语言和目标语言
if($_POST){
$source = 'zh-CN'; // 源语言为英文
$target = 'en'; // 目标语言为简体中文
// 获取待翻译的文本
$text=$_POST['text'];
// 构造谷歌翻译API的请求URL
$url = 'https://translation.googleapis.com/language/translate/v2?key=AIzaSyApV2SnkzCF9mrXDZqyM8mbvZpU-q0kS84&q=' . urlencode($text) . '&source=' . $source . '&target=' . $target;
// 发送HTTP请求并获取响应
$response = file_get_contents($url);
// 解析JSON格式的响应数据
$data = json_decode($response, true);
// 提取翻译结果
$translation = $data['data']['translations'][0]['translatedText'];
// 输出翻译结果
echo $translation;
}
?>
<form action="index.php" method="POST" style="max-width:800px;margin:0 auto">
<textarea id="message" name="text" placeholder="请输入消息" style="width:100%;height:500px"></textarea>
<input type="submit" value="中文翻译英文--点击翻译" style="width:100%;height:45px;text-align:center;background:#463480;color:#fff;border:0px;font-size:20px">
</form>
</body>
</html>