【发布时间】:2021-02-22 14:38:32
【问题描述】:
我正在做一项学校作业,我们需要将 textarea 中的输入“翻译”为数组中预先写好的单词。我不知道如何使选择的语言单选数组来搜索语言数组。
HTML
<html>
<head>
<title>
Translation PHP
</title>
</head>
<body>
<h1>Input your word and select the language you want to translate to.</h1>
<form action="form.php" method="GET/POST">
<p>Input your word for translation:</p>
<input type="text" name="inputword">
<p>Select language to translate to:</p>
<input type="radio" name="language" value="Swedish">Swedish<br>
<input type="radio" name="language" value="Italian">Italian<br>
<input type="radio" name="language" value="Spanish">Spanish<br>
<input type="radio" name="language" value="German">German<br>
<input type="radio" name="language" value="French">French<br>
<input type="submit" name="translate" value="Translate"/>
</form>
<br>
<p>Words available: Hello, Apple, Fruit, Car, Cat, Dog, Shoes, House, School, Sweatshirt</p>
</body>
</html>
PHP
<?php
$TranslateWord = $_GET['inputword'];
$choosenLanguage = $_GET['language'];
$English = array("Hello","Apple","Fruit","Car","Cat","Dog","Shoes","House","School","Sweatshirt");
$German = array("Hallo","Apfel","Obst","Wagen","Katze","Hund","Schuhe","Haus","Schule","Sweatshirt" );
$Swedish = array("Hej","Äpple","Frukt","Bil","Katt","Hund","Skor","Hus","Skola","Tröja");
$Italian = array("Ciao","Mela","Frutta","Macchina","Gatto","Cane","Scarpe","Casa","Scuola","Maglione");
$Spanish = array("Hola","Manzana","Fruta","Auto","Gato","Pero","Casa","Zapatos","Colegio","Sueter");
$French = array("Bonjour","Pomme","Fruit","Auto","Chat","Chien","Loger","Chaussures","l'ecole","Chandail");
$positionWord = array_search($TranslateWord, $English);
//This is where I need the language array to be found by the positionWord and choosen language radio in the form.
?>
如果我在之前的步骤中做错了什么,请告诉我,以便我学习如何改进。我尝试在数组中创建数组,但这只会给我更多错误。
【问题讨论】: