Advertisement
VanessaShopping

Celsius - Fahrenheit

Dec 25th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <DOCTYPE html>
  2.     <html>
  3.     <head><title>Converter</title></head>
  4.     <body>
  5.  
  6.     <?php
  7.  
  8.     function celToFah(float $celValueFromForm) : float
  9.     {
  10.         return $celValueFromForm * 1.8 + 32;
  11.     }
  12.  
  13.     function fahToCel(float $fahValueFromForm) : float
  14.     {
  15.         return ($fahValueFromForm - 32) / 1.8;
  16.     }
  17.  
  18.     ?>
  19.  
  20.  
  21.     <?php
  22.  
  23.     if (isset($_GET['celName'])) {
  24.         $celValueFromForm = floatval($_GET['celName']);
  25.         $fahValue = celToFah($celValueFromForm);
  26.         $fahMsg = "$celValueFromForm &deg;C = $fahValue &deg;F";
  27.     }
  28.     if (isset($_GET['fahName'])) {
  29.         $fahValueFromForm = floatval($_GET['fahName']);
  30.         $celValue = fahToCel($fahValueFromForm);
  31.         $celMsg = "$fahValueFromForm &deg;F = $celValue &deg;C";
  32.     }
  33.  
  34.     ?>
  35.  
  36.     <form>
  37.         Целзии: <input type="number" name="celName">
  38.         <input type="submit" value="Convert">
  39.         <?php
  40.         if (isset($fahMsg)) echo $fahMsg
  41.         ?>
  42.     </form>
  43.  
  44.     <form>
  45.         Фаренхайт: <input type="number" name="fahName">
  46.         <input type="submit" value="Convert">
  47.         <?php
  48.         if (isset($celMsg)) echo $celMsg
  49.         ?>
  50.     </form>
  51.  
  52.  
  53.     </body>
  54.     </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement