Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/textsträngar/

index.php
ovn_str1.php
ovn_str2.php
ovn_str4.php
ovn_str5.php
ovn_str6.php

ovn_str6.php

46 lines UTF-8 Windows (CRLF)
<?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>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>STRÄNGHANTERING</title>
</head>

<body>

    <?php

    
if (isset($_POST["str"])) { // Behöver bara checka en variabel
        
$consonants = ["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","z"];
        
$output "";
        
$str htmlspecialchars($_POST["str"]);

        for (
$i 0$i strlen($str); $i++) {
            
$char $str[$i];
            if (
in_array(strtolower($char), $consonants)) {
                
$output $output $char "o" $char;
            } else{
                
$output $output $char;
            }
        }

        echo(
$str "<br>");
        echo(
$output);
    }
    
?>
    <form method="POST">
        <input type="text" name="str" id="str_id" placeholder="Harry" required>
        <label for="str_id">Sträng att översätta</label><br>
        <button type="submit">Skicka in</button>
    </form>

</body>

</html>