|
|
<?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>";
?> |
|
| Reverse a given number Categories : PHP, Beginner Guides, Algorithms, Math. | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | | | Easy to use random number function that seeds with uniqid and allows a max value Categories : Math., PHP | | | Making a simple Hit-Log using PHP and MySql Categories : PHP, Log Files, Beginner Guides, Databases, MySQL | | | Newbie Notes #10 - Generating drop downs Categories : PHP, MySQL, HTML, Beginner Guides, Databases | | | Simple PHP cookie counter Categories : PHP, Cookies, 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 | | | decoct -- Decimal to octal Categories : PHP, PHP Functions, Math. | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | | | session out Timer Categories : PHP, Sessions, Security, Beginner Guides | | | Human readable PHP password generator Categories : PHP, Security, Beginner Guides, Arrays | | | Random text quote Categories : PHP, Arrays, Beginner Guides | | | How to Create a Shoutbox Using PHP & MySQL Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP | | | Find the day of the week for any given year/month/day. Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides | |
| |
| |
|