Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/exercises/strings/
11 filer
strings_1.php
strings_1_formreceive.php
strings_2.php
strings_2_formreceive.php
strings_3.php
strings_3_formreceive.php
strings_4.php
strings_4_formreceive.php
strings_5.php
strings_5_formreceive.php
strings_6.php
strings_1_formreceive.php
strings_2.php
strings_2_formreceive.php
strings_3.php
strings_3_formreceive.php
strings_4.php
strings_4_formreceive.php
strings_5.php
strings_5_formreceive.php
strings_6.php
strings_6.php
75 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Texsträngar 6</title>
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Arial;
}
#input {
height: 4em;
width: 20vw;
border: 1px solid gray;
margin: 1em 0;
}
#show-input, #show-output {
min-height: 5em;
max-width: 30vw;
border: 1px solid gray;
margin: 1em 1em 1em 0;
box-sizing: border-box;
padding: 0.3em;
font-size: 13.3333px;
font-family: Monospace;
}
</style>
</head>
<body>
<form method="post" action="">
<textarea id="input" name="inputText" placeholder="Skriv text här"></textarea><br>
<input type="submit" name="submitted" value="Översätt till rövarspråket"><br><br><br>
<div id="show-input">
<?php
if (isset($_POST["inputText"]) && $_POST["inputText"] !== "") {
$input = $_POST["inputText"];
echo $input;
?>
</div>
<strong>Blir på rövarspråket...</strong>
<div id="show-output">
<?php
$consonants = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "ñ", "p", "q", "r", "s", "t", "v", "w", "x", "z"];
$outputArray = [];
for ($i = 0; $i < mb_strlen($input); $i++) {
if (in_array(mb_strtolower($input[$i]), $consonants))
$outputArray[] = $input[$i] . "o" . mb_strtolower($input[$i]);
else
$outputArray[] = $input[$i];
}
echo implode($outputArray);
} else {
echo "Här visas resultatet";
}
?>
</div>
</form>
</body>
</html>