|
|
|
<?php
/*
Title: Temperature Conversion
Description: Convert celsius to fahrenheit and
fahrenheit to celsius.
Author: Murray Moffatt for A Web 4 U Designs
History:
2005-03-15 : Initial coding.
*/
function temp2celsius ($fahrenheit, $precision = 0) {
// Convert the supplied temperature in celsius to
// fahrenheit and return the value. Specify the required
// precision to round the converted value to.
// Returns FALSE on error.
if (!isset($fahrenheit)) return FALSE;
$precision = (integer)$precision;
$celsius = (float)(($fahrenheit - 32) / 1.8 );
return round($celsius, $precision);
}
function temp2fahrenheit ($celsius, $precision = 0) {
// Convert the supplied temperature in fahrenheit to
// celsius and return the value. Specify the required
// precision to round the converted value to.
// Returns FALSE on error.
if (!isset($celsius)) return FALSE;
$precision = (integer)$precision;
$fahrenheit = (float)(1.8 * $celsius) + 32;
return round($fahrenheit, $precision);
}
echo "<p>50F is " . temp2celsius(50) . "C</p>";
echo "<p>50C is " . temp2fahrenheit(50) . "F</p>";
?> |
|
| Math operations on big numbers Categories : PHP, Math. | | | Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | | | Introduction to Language Files Categories : PHP, Filesystem, Beginner Guides | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Newbie Notes #8 - A cron trick Categories : PHP, CURL, Beginner Guides | | | a PHP Function to Get only the filename (remove the extension) using regular expressions. Categories : PHP, Regexps, Beginner Guides | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | Beginners Array Functions Categories : PHP, Beginner Guides, Arrays | | | Easy alert box pop-up function Categories : PHP, Java Script, Beginner Guides | |
|
|
|