Temperature:

Code:

<html>
<head>
<title>PHP TEST YAHHH</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>

<div class="topbar">
<?php
include 'navbar.php';
?>
</div>

<?php

    
    //small form playground
    
    function fahrenheitToCelcius ($F)
    {
    
        $c = (($F-32)*(5/9));
        return $c;
    
    }
    
    function celciusToFahrenheit ($c)
    {
    
        $F = $c * 1.8 + 32;
        return $F;
    
    }
    
    define("THIS_PAGE", basename($_SERVER['PHP_SELF']));
    
    if (isset($_POST['temp']))
    {//show post data
    
        $scale = $_POST["scale"];
        $temp = $_POST["temp"];
        
        
        if ($scale == 'fahrenheit')
        {
        
            $newTemp = fahrenheitToCelcius($temp);
            $newScale = 'Celcius';
            
        }
        else
        {
        
            $newTemp = celciusToFahrenheit($temp);
            $newScale = 'Fahrenheit';
            
        }
        
        echo $temp;
        echo ' in ';
        echo $scale;
        echo ' is equal to ';
        echo $newTemp;
        echo ' in ';
        echo $newScale;
        echo '.';
        
    }
    else
    {//show form
    
        echo '
            <form action="'.THIS_PAGE.'" method="post">
            Temperature: <input type = "text" name = "temp"><br>
            <label for ="scale">Scale: </label>
                <select name = "scale" class="selector">
                    <option value = "celcius">Celcius to Fahrenheit</option>
                    <option value = "fahrenheit">Fahrenheit to Celcius</option>
                </select>
            <input type = "submit">
            </form>
        ';
        
    }//end if
    
    echo '<br>';
    
?>

<div class="codebox">
<h3>Code:</h3>
<?php
highlight_file(THIS_PAGE);
?>
</div>

</body>
</html>