Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/textstrangar/
ovn_text1.php
ovn_text2.php
ovn_text3.php
ovn_text4.php
ovn_text5.php
ovn_text6.php
ovn_text6.php
48 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Textsträng 6</title>
</head>
<body>
<form method="POST">
skriv in text: <br>
<input type="text" name="text" required>
<br><br>
<input type="submit" value="Omvandla till rövarspråk">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$text = $_POST['text'];
function rovarsprak($input){
$output = "";
$konsonanter = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
for ($i = 0; $i < strlen($input); $i++) {
$tecken = $input[$i];
if (strpos($konsonanter, $tecken) !== false) {
$output .= $tecken . 'o' . strtolower($tecken);
} else {
$output .= $tecken;
}
}
return $output;
}
$rovarsprak_text = rovarsprak($text);
echo "Vanlig text: ";
echo "$text";
echo "<br>";
echo "Text i rövarspråk: ";
echo $rovarsprak_text;
}
?>
</body>
</html>