Retour à 2iia.com

Convertisseur de Température



Code à copier

<!DOCTYPE html>
<html lang="fr">

<head>
    <meta charset="UTF-8">
    <title>Convertisseur de Température</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
            margin: 0;
            margin-top: 30px !important;
        }

        @media (max-width: 768px) {
            body {
                flex-direction: column;
                height: auto;
                padding: 20px;
                margin-top: 150 !important;
            }
        }

        .converter {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 400px;
            text-align: center;
        }

        h1 {
            font-size: 24px;
            color: #333 !important;
        }

        h2 {
            font-size: 20px;
            color: #555 !important;
            margin-top: 20px;
        }

        label {
            display: block;
            margin: 10px 0 5px;
            font-weight: bold;
            color: #333 !important;
        }

        input[type="number"],
        select {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 5px;
            box-sizing: border-box;
            color: #333 !important;
        }

        input[type="submit"],
        button {
            background-color: rgb(46, 26, 112);
            color: white;
            padding: 10px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            margin-top: 10px;
            color: white !important;
        }

        input[type="submit"]:hover,
        button:hover {
            background-color: rgb(72, 68, 190);
            color: white !important;
        }

        p {
            margin-top: 15px;
            font-size: 18px;
            color: #333 !important;
        }

        pre {
            background-color: #f8f8f8;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            text-align: left;
            max-height: 200px;
            overflow-y: auto;
        }

        code {
            font-family: 'Courier New', Courier, monospace;
            font-size: 14px;
        }
    </style>
</head>

<body>
    <div class="converter">
        <br>
        <a href="http://www.2iia.com" style="display: inline-block; background-color: #ff6200; color: white; padding: 15px 40px; border-radius: 5px; text-decoration: none; font-size: 16px; margin-bottom: 20px; text-align: center; margin: 0 auto; ">Retour à 2iia.com</a>
        <br><br>
        <h1>Convertisseur de Température</h1>
        <form method="POST" action="">
            <label>Entrez la température :</label>
            <input type="number" name="temperature" step="any" required><br>

            <label>Conversion :</label>
            <select name="type" required>
                <option value="c_to_f">Celsius → Fahrenheit</option>
                <option value="f_to_c">Fahrenheit → Celsius</option>
            </select><br>

            <input type="submit" value="Convertir">
        </form>

        <?php
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $temperature = floatval($_POST["temperature"]);
            $type = $_POST["type"];
            $resultat = "";

            if ($type == "c_to_f") {

                $resultat = ($temperature * 9 / 5) + 32;
                echo "<p>Résultat : $temperature °C = $resultat °F</p>";
            } elseif ($type == "f_to_c") {
                $resultat = ($temperature - 32) * 5 / 9;
                echo "<p>Résultat : $temperature °F = $resultat °C</p>";
            } else {
                echo "<p>Erreur : Type de conversion invalide.</p>";
            }
        }
        ?>

        <h2>Code à copier</h2>
        <pre><code id="code-to-copy"><?php echo htmlspecialchars(file_get_contents(__FILE__)); ?></code></pre>
        <button onclick="copyCode()">Copier le code</button>
    </div>

    <script>
        function copyCode() {
            var code = document.getElementById("code-to-copy").innerText;
            navigator.clipboard.writeText(code);
            alert("Code copié !");
        }
    </script>
</body>

</html>