Getting Started


1. Copy Files To Your Server

To start using Temperature Units Converter You need to copy TemperatureUnitsConverter folder with contents into Your server.

Recommended location that is used in samples of this documentation is /libs/TemperatureUnitsConverter/.


2. Include Library

After first step You need to include TemperatureUnitsConverter.lib.php file in Your PHP code.

<?php
include("libs/TemperatureUnitsConverter/TemperatureUnitsConverter.lib.php");
?>

3. That's All

Now, Temperature Units Converter is ready to use.

Want to know how to use? Please read next section of this documentation.

Basic Usage


Initialization

Code:

<?php
$converter = new TemperatureUnitsConverter();
?>

Conversion To Single Unit

Conversion of 77 reaumurs into kelvins.

Code:

<?php
echo $converter -> Convert("77 reaumurs", "kelvins");
?>

Result:

21128 kelvins


To exclude name of unit from result, just set third parameter to false, like in following example.

Code:

<?php
echo $converter -> Convert("77 reaumurs", "kelvins", true);
?>

Result:

21128


Conversion To Natural Language String

Conversion of 1770770 kelvins into delisles, newtons and rankines.

Code:

<?php
echo $converter -> Convert("1770770 kelvins", array("delisles", "newtons", "rankines"));
?>

Result:

4753 delisles, 1 newton and 144 rankines


You can customize format of result by providing additional params to Convert method.

Code:

<?php
echo $converter -> Convert("1770770 kelvins", array("delisles", "newtons", "rankines"), false, "[SEPARATOR]", "[LAST_SEPARATOR]");
?>

Result:

4753 delisles[SEPARATOR]1 newton[LAST_SEPARATOR]144 rankines


Unit Validation

To check if unit is supported You can call UnitExists method.

Code:

<?php
if($converter -> UnitExists("kelvin"))){
	
	echo "Unit exists.";
}
?>

Result:

Unit exists.


Getting List Of Supported Units

To check list of supported (installed) units, You can call GetUnits method.

Code:

<?php
$units = $converter -> GetUnits();

print_r($units);
?>

Result:

array(
	
	[0]	=>	[unit or alias], 
	[1]	=>	[unit or alias], 
	...
)


Parsing Value and Unit

Getting value and name of unit from given string.

Code:

<?php
$value_and_unit = $converter -> ExtractValueAndUnit("1 kelvin");

print_r($value_and_unit);
?>

Result:

array(
	
	[value]		=>	1, 
	[unit]		=>	"kelvins"
)

Methods


GetUnits()

GetUnits()

Gets list of all supported temperature units.

Parameters:

This method does not accept any parameters.

Returns:

array

Returns list of all supported temperature units.


UnitExists()

UnitExists($unit_name)

Checks if given unit exists (is supported).

Parameters:

$unit_name string Singular or plural form for name of unit that will be checked.

Returns:

boolean

Returns true when unit is supported, false otherwise.


ExtractValueAndUnit()

ExtractValueAndUnit($value_and_unit)

Extracts unit and value from given string.

Parameters:

$value_and_unit string Unit and value in string format.

Returns:

boolean  /  array

Returns array with temperature when unit was found, false otherwise.


Convert()

Convert($value_and_unit, $target_units = array(), $exclude_unit = false, $separator = ", ", $separator_last = " and ", $precision = 0)

Converts value and unit in string format to target format.

Parameters:

$value_and_unit string Unit and value to convert from.
$target_units string  /  array Singular or plural name(s) of single or multiple target units.
$exclude_unit boolean When set to true, result not contains names of units. Default value: false.
$separator string Separator for different units in result. Default value: ", ".
$separator_last string Separator that will be added before last value and unit in result. Default value: " and ".
$precision integer Number of decimal digits to round to (for last unit in result). Default value: 0.

Returns:

string  /  integer  /  float  /  boolean

Returns result of conversion on success, false otherwise.
Result may contain single or multiple, separated units that was specified in $target_units attribute.

Units


Temperature Units Converter supports 8 following units of temperature.


Singular Plural Description
Rankine Rankines = 0.5555555555555556 kelvins.
Kelvin Kelvins = Base unit.
Fahrenheit Fahrenheits = 255.92777777777778 kelvins.
Romer Romers = 260.76904761904757 kelvins.
Celsius Celsius = 274.15 kelvins.
Reaumur Reaumurs = 274.4 kelvins.
Newton Newtons = 276.180303030303 kelvins.
Delisle Delisles = 372.4833333333333 kelvins.

Dependencies and Limitations


Depedencies

Temperature Units Converter has no special depedencies.


Requirements

To use Temperature Units Converter we recommend PHP version 5 or greater.


Limitations

Conversion of small units into big ones (and vice versa) may result in returning "e-notation" results (eg. 1.0E+20).

Help and Support


If You have any question, You need any help or custom service, feel free to send message via our profile contact form.