PHP programming?
1.Write a program which can convert a temperature in Fahrenheit to the corresponding temperature in Celsius and vice versa? Im a new user to PHP so need help to study the PHP . I cant really understand the programm.
Public Comments
- Here's a simple PHP form that will do the trick. And If you're looking for a great site to learn PHP, go to: http://www.tizag.com/phpT/index.php <form action="<?php $PHP_SELF ?>" method="post"> Fahrenheit Temp: <input type="text" size="3" name="tf"> <br><br> Celsius Temp: <input type="text" size="3" name="tc"><br><br> <input type="submit" value="CONVERT"> </form> <br><br> <?php // Request the variables from the form. $tf = $_REQUEST['tf'] ; $tc = $_REQUEST['tc'] ; //To convert a Fahrenheit temperature to Celsius, we use the following formula: (5/9) * (F -32) //Since we need the 5/9 and the F - 32 value in parenthesis, we assign them to variables to make the procedure possible in PHP. $x = 5 / 9; $y = $tf - 32; $temp_c = $x * $y; // To convert a Celsius temperature to Fahrenheit we use the following: F = (9/5) * C + 32 $temp_f = 9 / 5 * $tc + 32; // Now we print the results: if ($tf) { echo "Temperature in Celsius is: <b> $temp_c </b>"; } if ($tc) { echo "Temperature in Fahrenheit is: <b> $temp_f </b>"; } ?>
Powered by Yahoo! Answers