Location: PHPKode > scripts > Conversion > conversion/example.php
<?php

header('Content-type: text/plain');

include_once('conversion.php');

try
{
	$conversion = new conversion();

	/*
	The difference between bi and byte is that the byte method
	uses the SI(1000) standard and bi the IEC(1024) standard.
	*/
	echo $conversion->bi(1024)           . "\n"; # should return 1 Kibi

	echo $conversion->bi(1666, 6)        . "\n"; # should return 1.626953 Kibi

	echo $conversion->byte(1024)         . "\n"; # should return 1,02 kB

	echo $conversion->meter(1000)        . "\n"; # should return 1 km

	echo $conversion->gram(1000)         . "\n"; # should return 1 kg

	echo $conversion->seconds(0.001)     . "\n"; # should return 1 ms

	/*
	You can also use user-defined values after the SI standard
	*/
	echo $conversion->si('foo', 1000)    . "\n"; # should return 1 kfoo

	echo $conversion->si('foo', 1000000) . "\n"; # should return 1 Mfoo
}
catch(Exception $e)
{
	echo 'something goes wrong';
}
Return current item: Conversion