forked from RedHatTraining/DO180-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
53 lines (44 loc) · 1.15 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<html>
<head>
<title>Converting Temperatures</title>
<meta charset="utf-8">
</head>
<body>
<form name="form1" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<table>
<tr>
<td>Enter the temperature to convert:</td>
<td><input type="text" name="temp" id="temp" size="10"></td>
</tr>
<tr>
<td>Convert to:</td>
<td><select name="scale" id="scale" size="1">
<option disabled>Select the scale</option>
<option value="c">Celsius</option>
<option value="f">Fahrenheit</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" name="btnConvert" id="btnConvert" value="Convert"></td>
<td><input type="reset" name="btnReset" id="btnReset" value="Reset"></td>
</tr>
</form>
<?php
function convert($value, $type){
if($type== "f"){
return (((9/5)*$value) +(32));
}
elseif ($type== "c"){
return (($value - 32) * (5/9));
}
}
if (isset($_POST['btnConvert'])) {
$temp = $_POST['temp'];
$scale = $_POST['scale'];
$converted = convert($temp, $scale);
echo "The original temperature, $temp, converted is $converted.";
}
?>
</body>
</html>