Webbserverprogrammering 1

Show sourcecode

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

ramverket/exercises/textstrangar/

ovn_textstr1.php
ovn_textstr2.php
ovn_textstr3.php
ovn_textstr4.php
ovn_textstr5.php

ovn_textstr1.php

45 lines UTF-8 Windows (CRLF)
<?php
  
// Title: Textsträngar 1
  
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>Textsträngar 1</title>
</head>
<body>
  <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST">
    <input type="text" name="first_name" placeholder="Förnamn">
    <input type="text" name="last_name" placeholder="Efternamn">
    <input type="email" name="email" placeholder="E-post">
    <button type="submit" value="Skicka">Skicka</button>
  </form>
  <?php 
    
if (empty($_POST)) {
      return;
    }

    
$first_name $_POST['first_name'] ?? '';
    
$last_name $_POST['last_name'] ?? '';
    
$email $_POST['email'] ?? '';

    
$first_name mb_strtolower($first_name);
    
$first_name ucfirst($first_name);
    
$last_name mb_strtolower($last_name);
    
$last_name ucfirst($last_name);

    echo 
htmlspecialchars("Namn: $first_name $last_name");
    echo 
'<br>';
    if (
mb_strpos($email'@') === false) {
      echo 
'E-post: OBS! Ogiltig e-post edress';
    } else {
      echo 
htmlspecialchars("E-post: $email");
    }
  
?>
</body>
</html>