jnt
05-22-2011, 10:21 AM
Hi, i am new in php and i want to make php page for converting units (lenght, time, weight etc.).
But before i start, i wanted to ask: is it smart to do this in php (js or something else)? And how did i started, what do you think about this code below?
Here is my idea:
<?php
$vre = $_POST['vrednost'];
$jed = $_POST['jed'];
$ujed = $_POST['ujed'];
if ($jed == "celsius")
switch ($ujed){
case "celsius":
echo "Same thing.";
break;
case "farenheit":
echo (number_format(($vre*(9/5)+32),2));
break;
case "kelvin":
echo (number_format(($vre + 273.15),2));
break;
}
elseif ($jed == "farenheit")
switch ($ujed){
case "celsius":
echo (number_format((($vre-32)*(5/9)),3));
break;
case "farenheit":
echo "Same thing.";
break;
case "kelvin":
echo (number_format((($vre+459.67)*(5/9)),3));
break;
}
elseif ($jed == "kelvin")
switch ($ujed){
case "celsius":
echo (number_format(($vre-273.15),2));
break;
case "farenheit":
echo (number_format(($vre * (9/5) - 459.67),2));
break;
case "kelvin":
echo "Same thing.";
break;
}
But before i start, i wanted to ask: is it smart to do this in php (js or something else)? And how did i started, what do you think about this code below?
Here is my idea:
<?php
$vre = $_POST['vrednost'];
$jed = $_POST['jed'];
$ujed = $_POST['ujed'];
if ($jed == "celsius")
switch ($ujed){
case "celsius":
echo "Same thing.";
break;
case "farenheit":
echo (number_format(($vre*(9/5)+32),2));
break;
case "kelvin":
echo (number_format(($vre + 273.15),2));
break;
}
elseif ($jed == "farenheit")
switch ($ujed){
case "celsius":
echo (number_format((($vre-32)*(5/9)),3));
break;
case "farenheit":
echo "Same thing.";
break;
case "kelvin":
echo (number_format((($vre+459.67)*(5/9)),3));
break;
}
elseif ($jed == "kelvin")
switch ($ujed){
case "celsius":
echo (number_format(($vre-273.15),2));
break;
case "farenheit":
echo (number_format(($vre * (9/5) - 459.67),2));
break;
case "kelvin":
echo "Same thing.";
break;
}