Files
RobinNixon 53063593e3 Final
Final
2020-12-10 13:51:13 +00:00

47 lines
1021 B
PHP

<?php // convert.php
$f = $c = '';
if (isset($_POST['f'])) $f = sanitizeString($_POST['f']);
if (isset($_POST['c'])) $c = sanitizeString($_POST['c']);
if (is_numeric($f))
{
$c = intval((5 / 9) * ($f - 32));
$out = "$f &deg;f equals $c &deg;c";
}
elseif(is_numeric($c))
{
$f = intval((9 / 5) * $c + 32);
$out = "$c &deg;c equals $f &deg;f";
}
else $out = "";
echo <<<_END
<html>
<head>
<title>Temperature Converter</title>
</head>
<body>
<pre>
Enter either Fahrenheit or Celsius and click on Convert
<b>$out</b>
<form method="post" action="convert.php">
Fahrenheit <input type="text" name="f" size="7">
Celsius <input type="text" name="c" size="7">
<input type="submit" value="Convert">
</form>
</pre>
</body>
</html>
_END;
function sanitizeString($var)
{
if (get_magic_quotes_gpc())
$var = stripslashes($var);
$var = htmlentities($var);
$var = strip_tags($var);
return $var;
}
?>