1. Computing & Technology

Discuss in my forum

Convert Temperature

By , About.com Guide

Adding More Conversions
Still working in our convert.php file, add the following code at the end of the document, just before the ?> end PHP tag.

 if ($scale == "fahrenheit") 
 {print "<table border><tr><th colspan=2> Conversion Results</th></tr><tr><td>$degree</td><td>farhenheit</td></tr>"; 
 $f_2_c = ($degree -32)*5/9; 
 print "<tr><td>$f_2_c</td><td>celsius</td></tr>"; 
 $f_2_k = $f_2_c+273.15; 
 print "<tr><td>$f_2_k </td><td>kelvin</td></tr>"; 
 $f_2_r = $degree+459.6; 
 print "<tr><td>$f_2_r</td><td>rankine</td></tr></table>";} 
 
 if ($scale == "kelvin") 
 {print "<table border><tr><th colspan=2> Conversion Results</th></tr><tr><td> 
 $degree</td><td>kelvin</td></tr>"; 
 $k_2_f = ($degree - 273.15) * 9 / 5 + 32; 
 print "<tr><td>$k_2_f</td><td>fahrenheit</td></tr>"; 
 $k_2_c = $degree-273.15; 
 print "<tr><td>$k_2_c </td><td>celsius</td></tr>"; 
 $k_2_r = $k_2_f+459.6; 
 print "<tr><td>$k_2_r</td><td>rankine</td></tr></table>";} 
 
 if ($scale == "rankine") 
 {print "<table border><tr><th colspan=2> Conversion Results</th></tr><tr><td>$degree</td><td>rankine</td></tr>"; 
 $r_2_f = $degree-459.6; 
 print "<tr><td>$r_2_f</td><td>fahrenheit</td></tr>"; 
 $r_2_c = ($r_2_f - 32)*5/9; 
 print "<tr><td>$r_2_c </td><td>celsius</td></tr>"; 
 $r_2_k = $r_2_c + 273.15; 
 print "<tr><td>$r_2_k</td><td>kelvin</td></tr></table>";} 
and put this code after the ?> closing PHP tag to close up our HTML

</body> 
 </html> 

©2012 About.com. All rights reserved.

A part of The New York Times Company.