<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$temperature = $_POST['temperature'];
$unit = $_POST['unit'];
$result = '';
if ($unit == 'C') {
// Konwersja z Celsjusza
$fahrenheit = ($temperature * 9/5) + 32;
$kelvin = $temperature + 273.15;
$result = "Fahrenheit: " . round($fahrenheit, 2) . " °F, Kelvin: " . round($kelvin, 2) . " K";
} elseif ($unit == 'F') {
// Konwersja z Fahrenheita
$celsius = ($temperature - 32) * 5/9;
$kelvin = $celsius + 273.15;
$result = "Celsjusz: " . round($celsius, 2) . " °C, Kelvin: " . round($kelvin, 2) . " K";
} else {
// Konwersja z Kelwina
$celsius = $temperature - 273.15;
$fahrenheit = ($celsius * 9/5) + 32;
$result = "Celsjusz: " . round($celsius, 2) . " °C, Fahrenheit: " . round($fahrenheit, 2) . " °F";
}
echo "<div class='alert alert-success text-center'>Wynik: $result</div>";
}
?>
</div>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4"> <!-- Użycie klas Bootstrap do szerokości i wyśrodkowania -->
<h1 class="text-center">Kalkulator Temperatur</h1>
<form method="post" class="form-horizontal">
<div class="form-group">
<label for="temperature" class="col-sm-2 control-label">Temperatura</label>
<div class="col-sm-10">
<input type="number" name="temperature" id="temperature" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="unit" class="col-sm-2 control-label">Jednostka</label>
<div class="col-sm-10">
<select name="unit" id="unit" class="form-control" required>
<option value="C">Celsjusz (°C)</option>
<option value="F">Fahrenheit (°F)</option>
<option value="K">Kelwin (K)</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Oblicz</button>
</div>
</div>
</form>
</div>
</div>
</div>
Cytat
<!-- Użycie klas Bootstrap do szerokości i wyśrodkowania -->