<?php
/**
 * Praktikum DBWT. Autoren:
 * Şafak, Hazinedar, 3108590
 * Robert, Joel, 3672729
 */

const GET_PARAM_SEARCH_TEXT = 'search_text';

$searchTerm = "";

if (!empty($_GET[GET_PARAM_SEARCH_TEXT])) {
    $searchTerm = $_GET[GET_PARAM_SEARCH_TEXT];

}

$enFile = fopen("en.txt", "r");
$fileLines = [];
while ($line = fgets($enFile)) {
    $fileLines[] = $line;
}

$found = false;
foreach ($fileLines as $line){
    $lineArray[] = explode(';', $line);
    $deutsch = $lineArray[0][0];
    if(strtolower($deutsch)==strtolower($searchTerm)){
        $found = true;
        echo $searchTerm." bedeutet ".$lineArray[0][1];
    }
    unset($lineArray);
}
if(!$found){
    if(!empty($searchTerm)){
        echo "Das gesuchte Wort ".$searchTerm." ist nicht enthalten";
    }
}


?>

<form method="get">
    <label for="search_text">Suche:</label>
    <input id="search_text" type="text" name="search_text" value=<?php echo $searchTerm?>>
    <input type="submit" value="Suchen">
</form>