Wednesday, February 10, 2021

Temperature Converter in PHP

 A program that allows the user to select temperature celsius to Fahrenheit and vice versa using PHP programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Thank you very much.





Program Listing

style.css

* {
    box-sizing: border-box;
}


body {
    font-family: Arial, Helvetica, sans-serif;
    background: url("double-bubble-outline.png") #fefefe repeat;
    color: #1a1a1a;
    font-size: 15px;
}

main {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 500px;
    box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
    border-radius: 10px;
}

.container {
    display: block;
    padding: 30px;
    background: #fff;
    text-align: left;
    border-radius: 2px;
}

h1, h2 {
    text-align: center;
}

label {
    width: 100%;
}

input,
select {
    display: inline-block;
    background: #f5f5f5;
    width: 100%;
    margin: 5px 0 20px 0;
    padding: 15px;
    border: none;
    font-size: 15px;
}

input:focus,
select:focus {
    background: #eeeeee;
    outline: none;
}

.btnReset,
button {
    background: #2196f3;
    color: #fff;
    padding: 15px;
    margin: 0 0 20px;
    border: none;
    cursor: pointer;
    width: 100%;
    opacity: 0.9;
    font-size: 15px;
    outline: none;
    border:0;
}

.btnWrapper {
    display: flex;
    margin: 0 0 20px;
}

.btnReset {
    background: #4caf50;
}

.btnReset,
.btnConvert {
    width: 50%;
    display: inline-block;
    text-align: center;
    text-decoration: none;
    margin: 0;
}

.btnSelectShape {
    background: #f44336;
}

.btnReset:hover,
button:hover {
    opacity: 1;
}

.answer {
    width: 100%;
    padding: 20px;
    text-align: center;
    font-size: 30px;
    font-weight: bold;
    background: #dadada;
    font-family: 'Times New Roman', serif;
    line-height: 1.5;
}

.visibility_on {
    display: block;

}

.visibility_off {
    display: none;
}

.frmTempSelect {  
    display: flex;
    flex-flow: row wrap;
    align-items: center;
}

.frmTempSelect select {
    vertical-align: middle;
    padding: 15px;
    margin: 5px 0 0;
    width: calc(100% - 100px);
}

.frmTempSelect button {
    width: 100px;
    margin: 5px 0 0;
}

.pieText {
    font-family: Serif;
}
.blueText {
    color:#2196f3;
}


index.php

<?php 
  /* Temperature Converter in PHP
     Mr. Jake Rodriguez Pomperada, MAED-IT, MIT
     www.jakerpomperada.com  / www.jakerpomperada.blogspot.com
     jakerpomperada@gmail.com 
     Bacolod City, Negros Occidental Philippines
   */

    $area = $html = $infotext = $sel1 = $sel2 = $sel3 = "";
    $num1 = isset($_POST['txtNum1']) ? floatval($_POST['txtNum1']) : "";
    $visibility = "visibility_off";
    $frmArea = isset($_GET['selectArea']) ? $_GET['selectArea'] : '';

    // Display selected shape input fields
    if(isset($_GET['selectArea'])) {
        $visibility = "visibility_on";

        switch ($frmArea) {
            case "ctof":
                $sel1 = "selected";
                $html = '<h2>Celsius &#8594; Fahrenheit Converter</h2>
                        <label for="txtNum1"><b>Input Temparature in &#8451;:</b></label>
                        <input type="number" name="txtNum1" id="txtNum1" value="'.$num1.'" required>';
                if(isset($_POST['btnConvert'])) {
                    $temp = round((($num1 * (9/5))+32), 2);
                    $infotext = '<div class="answer">(<span class="blueText">'.$num1.'</span> x <sup>9</sup>&#8260;<sub>5</sub>) + 32 = '.$temp.' &#8457;</div>';
                }
                break;
            case "ftoc":
                $sel2 = "selected";
                $html = '<h2>Fahrenheit &#8594; Celsius Converter</h2>
                        <label for="txtNum1"><b>Input Temparature in &#8457;:</b></label>
                        <input type="number" name="txtNum1" id="txtNum1" value="'.$num1.'" required>';
                if(isset($_POST['btnConvert'])) {
                    $temp = round((($num1 - 32) * (5/9)), 2);
                    $infotext = '<div class="answer">(<span class="blueText">'.$num1.'</span> - 32) x <sup>5</sup>&#8260;<sub>9</sub> = '.$temp.' &#8451;</div>';
                }
                break;
        }
    }
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Temperature Converter in PHP</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <main>
            <div class="container">
                <h1>Temperature Converter in PHP</h1>
                <h2>Mr. Jake R. Pomperada, MAED-IT, MIT</h2>
            </div>

            <div class="container">
                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" class="frmTempSelect">
                    <label for="selectArea"><b>Select Unit of Temperature:</b></label>
                    <select name="selectArea" id="selectArea" value="<?php echo $oper; ?>" required>
                        <option value="ctof" <?php echo $sel1; ?>>Celsius &#8594; Fahrenheit</option>
                        <option value="ftoc" <?php echo $sel2; ?>>Fahrenheit &#8594; Celsius</option>
                    </select>

                    <button type="submit" class="btnSelectShape">Select</button>
                </form>
            </div>

            
            <div class="container <?php echo $visibility; ?>">
                <form action="" method="post" class="frmAreaCalculate">
                    <?php echo $html; ?>
                    
                    <div class="btnWrapper">
                        <a href="index.php" type="button" name="btnReset" class="btnReset">Reset</a>
                        <button type="submit" name="btnConvert" class="btnConvert">Convert</button>
                    </div>

                    <?php echo $infotext; ?>
                </form>
            </div>
        </main>
    </body>
</html>

No comments:

Post a Comment