Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Crisu83/php-conversion
Library for converting units and sizes in PHP
https://github.com/Crisu83/php-conversion
Last synced: about 1 month ago
JSON representation
Library for converting units and sizes in PHP
- Host: GitHub
- URL: https://github.com/Crisu83/php-conversion
- Owner: crisu83
- License: apache-2.0
- Created: 2013-10-18T22:46:17.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-06-15T20:21:42.000Z (over 2 years ago)
- Last Synced: 2024-10-30T00:39:50.647Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 88.9 KB
- Stars: 130
- Watchers: 6
- Forks: 19
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-php - PHP Conversion - Another library for converting between units of measure. (Table of Contents / Numbers)
- awesome-php-cn - PHP Conversion - 另一个库之间的转换单位的措施. (目录 / 数字 Numbers)
- awesome-projects - PHP Conversion - Another library for converting between units of measure. (PHP / Numbers)
- awesome-php - PHP Conversion - Another library for converting between units of measure. (Table of Contents / Numbers)
README
php-conversion
==============
[![Build Status](https://travis-ci.org/crisu83/php-conversion.png?branch=master)](https://travis-ci.org/crisu83/php-conversion)Library for converting units and sizes in PHP.
## Units supported
* Acceleration
* Angle
* Area
* Digital information
* Electric current
* Frequency
* Fuel consumption
* Length
* Luminous Intensity
* Mass
* Power
* Pressure
* Speed
* Temperature
* Time
* Velocity
* Voltage
* Volume## Sizes supported
* Hat size
* Child shoe size## Number base supported
* Binary
* Octal
* Decimal
* Hexadecimal## Usage
Example usage:
```php
use Crisu83\Conversion\Quantity\DigitalInformation\DigitalInformation;
use Crisu83\Conversion\Quantity\Length\Length;
use Crisu83\Conversion\NumberBase\NumberBase;
use Crisu83\Conversion\Size\HatSize\HatSize;
use Crisu83\Conversion\Size\ShoeSize\ChildShoeSize;use Crisu83\Conversion\Quantity\Length\Unit as LengthUnit;
use Crisu83\Conversion\Quantity\DigitalInformation\Unit as DIUnit;
use Crisu83\Conversion\Size\HatSize\System as HatSizeSystem;
use Crisu83\Conversion\Size\ShoeSize\System as ShoeSizeSystem;require(dirname(__DIR__) . '/vendor/autoload.php');
$length = new Length(1, LengthUnit::METRE);
echo $length . '
';
echo $length->add(1, LengthUnit::FOOT) . '
';
echo $length->add(5)->sub(2, LengthUnit::FOOT) . '
';
echo $length->to(LengthUnit::YARD) . '
';echo '
';$di = new DigitalInformation(1000, DIUnit::MEGABYTE);
echo $di . '
';
echo $di->to(DIUnit::BIT)->out(2, '.', '') . '
';
echo $di->to(DIUnit::GIGABIT) . '
';
echo $di->to(DIUnit::TERABYTE)->out(10) . '
';echo '
';$number = new NumberBase("0xff", NumberBase::HEXADECIMAL);
echo $number . '
';
echo $number->to(NumberBase::DECIMAL) . '
';
echo $number->to(NumberBase::OCTAL) . '
';
echo $number->to(NumberBase::BINARY) . '
';echo '
';$hatSize = new HatSize(40, HatSizeSystem::CENTIMETRE);
echo $hatSize . '
';
echo $hatSize->to(HatSizeSystem::AMERICAN) . '
';
echo $hatSize->to(HatSizeSystem::BRITISH) . '
';
echo $hatSize->to(HatSizeSystem::INCH) . '
';echo '
';$shoeSize = new ChildShoeSize(20, ShoeSizeSystem::EUROPEAN);
echo $shoeSize . '
';
echo $shoeSize->to(ShoeSizeSystem::AMERICAN) . '
';
echo $shoeSize->to(ShoeSizeSystem::BRITISH) . '
';
echo $shoeSize->to(ShoeSizeSystem::INCH) . '
';
```Sample output:
```
1.00 m
1.30 m
5.70 m
6.23 yd1,000.00 MB
8388629474.89 b
7.81 Gb
0.0009534451 TB0xff
255
o377
b1111111140 cm
4 US
4 7/8 UK
15.748 in20 EUR
4.5 - 5 US
3.5 - 4 UK
4.625 in
```