PHP Practical Slip 11 Q.A

Write a PHP Script which will convert temperatures from Celsius(C)to Fahrenheit
(F). (Hint: C=5.0/9(F-32).

<!DOCTYPE html>
<html>
<head>
    <title>Celsius to Fahrenheit Converter</title>
</head>
<body>
    <h2>Convert Celsius to Fahrenheit</h2>

    <form method="post">
        Enter Temperature in Celsius: 
        <input type="number" name="celsius" step="0.01" required>
        <input type="submit" value="Convert">
    </form>

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $celsius = $_POST['celsius'];

        // Convert Celsius to Fahrenheit using formula: F = (C × 9/5) + 32
        $fahrenheit = ($celsius * 9/5) + 32;

        echo "<h3>Temperature:</h3>";
        echo "Celsius: " . $celsius . "°C<br>";
        echo "Fahrenheit: " . round($fahrenheit, 2) . "°F";
    }
    ?>
</body>
</html>
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top