Umrechnen in verschiedene Temperatureinheiten
Rechnet Temperaturen in Kelvin ,Celsius, Fahrenheit ,Rankine ,Newton,Reaumur ,Rømer um
Der hier verwendete Code
<?php
$d = "°";
$scales = array(
//°C = (K + -273.15) * 1
"Kelvin" => array(
"unit" => "K",
"add" => -273.15,
"mult" => 1,
),
//°C = (K + 0) * 1
"Celcius" => array(
"unit" => $d."C",
"add" => 0,
"mult" => 1,
),
//°C = (°F + -32) * 5/9
"Fahrenheit" => array(
"unit" => $d."F",
"add" => -32,
"mult" => (5/9),
),
//°C = (R + -491.67) * 5/9
"Rankine" => array(
"unit" => "R",
"add" => -491.67,
"mult" => (5/9),
),
//°C = (°N + -491.67) * 100/33
"Newton" => array(
"unit" => $d."N",
"add" => -491.67,
"mult" => (100/33),
),
//°C = (°Ré + 0) * 5/4
"Réaumur" => array(
"unit" => $d."Ré",
"add" => 0,
"mult" => (5/4),
),
//°C = (°Rø + -7.5) * 40/21
"Rømer" => array(
"unit" => $d."Rø",
"add" => -7.5,
"mult" => (40/21),
),
);
function convert($fromscale, $fromvalue, $toscale) {
if ($fromvalue != "") {
global $scales;
$Celcius = ($fromvalue + $scales[$fromscale]["add"]) * $scales[$fromscale]["mult"];
$output = ($Celcius * (1 / $scales[$toscale]["mult"])) - $scales[$toscale]["add"];
return $output;
}
}
foreach ($scales as $name => $data) {
if ($_POST[$name] != "") {
$inputvalue = $_POST[$name];
$inputscale = $name;
}
}
?>
<!DOCTYPE HTML >
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
<TITLE>Temperature Converter</TITLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<TABLE HEIGHT=100% WIDTH=100%>
<COL WIDTH=100%>
<TR>
<TD COLSPAN=1 WIDTH=100% VALIGN=CENTER>
<CENTER>
<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=3>
<TR>
<TD>
<CENTER>
<H3>Temperature Converter</H3>
</CENTER>
<HR/>
<TABLE>
<TR>
<!-- Begin php script -->
<?php
foreach ($scales as $name => $data) {
echo "<TD VALIGN=\"CENTER\">\n";
echo "\t<FORM METHOD=\"POST\" ACTION=\"\" NAME=\"$name\">\n";
echo "\t\t<CENTER>\n";
echo "\t\t\t" . $name . " (" . $data["unit"] . ")\n";
echo "\t\t</CENTER>\n";
echo "\t\t<CENTER>\n";
echo "\t\t\t<INPUT TYPE=\"TEXT\" NAME=\"$name\" SIZE=\"16\" VALUE=\"" . convert($inputscale, $inputvalue, $name) . "\">\n";
echo "\t\t</CENTER>\n";
echo "\t\t<CENTER>\n";
echo "\t\t\t<INPUT TYPE=\"SUBMIT\" VALUE=\"Convert\"/>\n";
echo "\t\t</CENTER>\n";
echo "\t</FORM>\n";
echo "</TD>\n";
}
?>
<!-- End php script -->
</TR>
</TABLE>
<HR/>
<CENTER>
<TABLE CELLPADDING=4 >
</TABLE>
</CENTER>
</TD>
</TR>
</TABLE>
</CENTER>
</TD>
</TR>
</TABLE>
</BODY>
</html>