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_textstr3.php

38 lines UTF-8 Windows (CRLF)
<?php
  
// Title: Textsträngar 3
  
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 3</title>
</head>
<body>
  <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST">
    <input type="number" name="nr1" placeholder="Tal">
    <input type="number" name="nr2" placeholder="Tal">
    <button type="submit" value="Skicka">Skicka</button>
  </form>
  <?php 
    
if (empty($_POST)) {
      return;
    }

    
$nr1 $_POST['nr1'] ?? '';
    
$nr2 $_POST['nr2'] ?? '';

    if (
$nr1 == '' || $nr2 == '') {
      echo 
'OBS! Talen kan inte vara tomma!';
      return;
    }

    
$string "$nr1 / $nr2 = " round($nr1 $nr22);
    echo 
htmlspecialchars($string);
  
?>
</body>
</html>