PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Christoph Kappestein  >  Conversion  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example script
Class: Conversion
Convert values between metric and binary systems
Author: By
Last change: correct a comment
Date: 5 years ago
Size: 966 bytes
 

Contents

Class file image Download
<?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';
}