=====Unit Converter===== (GmBowen:) Mark & I modified another script so that it could be an action that could do unit conversions. (doesn't do gallons yet....maybe I'll add that later). Save the following code as ##actions/unitconverter.php## and call it with ""{{unitconverter}}"". %%(php)

Enter a number:  

Change that number from...

 

 © 2002 by Bill Pellowe

"; // remove commas and spaces trim($value1); $valuetemp = str_replace(",", "", $value1); $value = str_replace(" ", "", $valuetemp); if(!(is_numeric($value))) { $value=""; $msg_warn = "

Type a number, no letters.

"; } // get the first character in the value to later check that it's not a letter $check = substr($value, 0, 1); // in case no number is entered, the page refreshes if ($value == "") { // echo "

Conversion Tool\"PHP\"

"; echo $msg_warn; echo ""; echo "
"; echo "$form_block"; } else if (($check != "0") && ($check != "1") && ($check != "2") && ($check != "3") && ($check != "4") && ($check != "5") && ($check != "6") && ($check != "7") && ($check != "8") && ($check != "9") && ($check != ".") && ($check != "-")) { // oddly the quotes were needed above around 0 etc for absolute values otherwise letters parsed through echo "

Conversion Tool

"; echo ""; echo "
"; echo "$form_block"; } else { { if ($value == 1) { $plural = ""; } else $plural = "s"; } switch($convert) { case "celfar": $result = ($value*1.8) +32; $unit1 = "degree"; $unit1 .= $plural; $unit1 .= " celsius (C)"; $unit2 = "degrees fahrenheit (F)"; break; case "farcel": $result = ($value - 32) * 0.5556; $unit1 = "degree"; $unit1 .= $plural; $unit1 .= " fahrenheit (F)"; $unit2 = "degrees celsius (C)"; break; case "cmin": $result = $value * 0.393701; $unit1 = "centimeter"; $unit1 .= $plural; $unit2 = "inches"; break; case "incm": $result = $value * 2.54; $unit1 = "inch"; if ($plural == "s") { $plural = "es"; } $unit1 .= $plural; $unit2 = "centimeters"; break; case "mefe": $result = $value * 3.28084; $unit1 = "meter"; $unit1 .= $plural; $unit2 = "feet"; break; case "feme": $result = $value * 0.3048; if ($plural != "s") { $unit1 = "foot"; } else { $unit1 = "feet"; } $unit2 = "meters"; break; case "kmmi": $result = $value * 0.621371; $unit1 = "kilometer"; $unit1 .= $plural; $unit1 .= " (km)"; $unit2 = "miles (mi)"; break; case "mikm": $result = $value * 1.60934; $unit1 = "mile"; $unit1 .= $plural; $unit1 .= " (mi)"; $unit2 = "kilometers (km)"; break; case "kglb": $result = $value * 2.20462; $unit1 = "kilogram"; $unit1 .= $plural; $unit1 .= " (kg)"; $unit2 = "pounds (lb)"; break; case "lbkg": $result = $value * 0.453592; $unit1 = "pound"; $unit1 .= $plural; $unit1 .= " (lb)"; $unit2 = "kilograms (kg)"; break; case "mloz": $result = $value * 0.0338146; $resultUK = $value * 0.035195083; $unit1 = "milliliter"; $unit1 .= $plural; $unit1 .= " (ml)"; $unit2 = "U.S. ounces (oz), or "; $unit2 .= number_format($resultUK, "3", ".", ","); $unit2 .= " ounces in British measurement.
(1 US oz is 1.0408 UK oz)"; break; case "ozml": $result = $value * 29.57303; $resultUK = $value * 28.41306; $unit1 = "ounce"; $unit1 .= $plural; $unit1 .= " (oz)"; $unit2 = "milliliters, but only if you're using US ounces.
If you're using British ounces, the answer is "; $unit2 .= number_format($resultUK, "2", ".", ","); $unit2 .= " milliliters (because one US oz is 1.0408 UK oz)"; break; case "rbtb": $result = $value * 0.75; $unit1 = "regular-size can"; $unit1 .= $plural; $unit1 .= " (350 ml, or 12 oz) of beer"; $unit2 = "tall cans (500 ml, or 16 oz) of beer.
(It doesn't matter if you have ml or oz beers; the difference in the ratio between ml and oz beers is only 0.000005 cans of beer.)"; break; case "tbrb": $result = $value * 1.33; $unit1 = "tall can"; $unit1 .= $plural; $unit1 .= " (500 ml, or 16 oz) of beer"; $unit2 = "regular cans (350 ml, or 12 oz) of beer.
(It doesn't matter if you have ml or oz beers; the difference in the ratio between ml and oz beers is only 0.000005 cans of beer.)"; break; } echo "

Conversion Tool$php_link

"; echo "Result of your conversion:

"; echo ""; echo "
"; echo "

You can do another conversion if you'd like:

"; echo "$form_block"; } ?> %% CategoryUserContributions