YavorGrancharov

Celsius - Fahrenheit

Dec 2nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2.     function celsiusToFahrenheit(float $celsius) {
  3.         return $celsius * 9/5 + 32;
  4.     }
  5.     function fahrenheitToCelsius(float $fahrenheit) {
  6.         return ($fahrenheit - 32) * 5/9;
  7.     }
  8.     $msgCel = "";
  9.     if (isset($_GET['cel'])) {
  10.         $celsius = floatval($_GET['cel']);
  11.         $degrees = celsiusToFahrenheit($celsius);
  12.         $msgCel = "$celsius &deg;C = $degrees &deg;F";
  13.     }
  14.     $msgFah = "";
  15.     if (isset($_GET['fah'])) {
  16.         $fahrenheit = floatval($_GET['fah']);
  17.         $degrees = fahrenheitToCelsius($fahrenheit);
  18.         $msgCel = "$fahrenheit &deg;F = $degrees &deg;C";
  19.     }
  20. ?>
  21. <form>
  22.     Celsius: <input type="text" name="cel"/>
  23.     <input type="submit" value="Convert">
  24.     <?= $msgCel ?>
  25. </form>
  26. <form>
  27.     Fahrenheit: <input type="text" name="fah"/>
  28.     <input type="submit" value="Convert"><?= $msgFah ?>
  29. </form>
Add Comment
Please, Sign In to add comment