CancelImage Upload

How to convert Temperature Fahrenheit into Celsius and back again in PHP

The tutorial on this page explains how to convert between Degrees Fahrenheit and Celsius in PHP. If you are only looking to translate a specific temperature without doing any programming try our temperature converter.

If you are writing a PHP application that is dealing with data related to weather conditions you will no doubt at some point have to convert between Celsius and Fahrenheit. To perform these conversions two simple formulas are required.

To convert Fahrenheit into Celsius:

°C = (°F - 32) /1.8

And to convert Celsius into Fahrenheit:

°F = (°C * 1.8) + 32

In PHP terms these two formulas translate into the following code. For Fahrenheit into Celsius:

<?php

$fahrenheit = 90;

$celsius = ($fahrenheit - 32) / 1.8;

echo "The temperature is ".$celsius." &deg;C";

?>

And for Celsius into Fahrenheit of course we reverse the formula:

<?php

$celsius = 18;

$fahrenheit = ($celsius * 1.8) + 32;

echo "The temperature is ".$fahrenheit." &deg;F";

?>

As you can see it's nothing too complicated once you know the formulas.

Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com