Library for converting units and sizes in PHP

Overview

php-conversion

Build Status

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:

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 . '<br>';
echo $length->add(1, LengthUnit::FOOT) . '<br>';
echo $length->add(5)->sub(2, LengthUnit::FOOT) . '<br>';
echo $length->to(LengthUnit::YARD) . '<br>';

echo '<br>';

$di = new DigitalInformation(1000, DIUnit::MEGABYTE);
echo $di . '<br>';
echo $di->to(DIUnit::BIT)->out(2, '.', '') . '<br>';
echo $di->to(DIUnit::GIGABIT) . '<br>';
echo $di->to(DIUnit::TERABYTE)->out(10) . '<br>';

echo '<br>';

$number = new NumberBase("0xff", NumberBase::HEXADECIMAL);
echo $number . '<br>';
echo $number->to(NumberBase::DECIMAL) . '<br>';
echo $number->to(NumberBase::OCTAL) . '<br>';
echo $number->to(NumberBase::BINARY) . '<br>';

echo '<br>';

$hatSize = new HatSize(40, HatSizeSystem::CENTIMETRE);
echo $hatSize . '<br>';
echo $hatSize->to(HatSizeSystem::AMERICAN) . '<br>';
echo $hatSize->to(HatSizeSystem::BRITISH) . '<br>';
echo $hatSize->to(HatSizeSystem::INCH) . '<br>';

echo '<br>';

$shoeSize = new ChildShoeSize(20, ShoeSizeSystem::EUROPEAN);
echo $shoeSize . '<br>';
echo $shoeSize->to(ShoeSizeSystem::AMERICAN) . '<br>';
echo $shoeSize->to(ShoeSizeSystem::BRITISH) . '<br>';
echo $shoeSize->to(ShoeSizeSystem::INCH) . '<br>';

Sample output:

1.00 m
1.30 m
5.70 m
6.23 yd

1,000.00 MB
8388629474.89 b
7.81 Gb
0.0009534451 TB

0xff
255
o377
b11111111

40 cm
4 US
4 7/8 UK
15.748 in

20 EUR
4.5 - 5 US
3.5 - 4 UK
4.625 in
You might also like...
Library for converting units and sizes in PHP

php-conversion Library for converting units and sizes in PHP. Units supported Acceleration Angle Area Digital information Electric current Frequency F

YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

La Fattura is a system designed for companies and individuals of all sizes to manage invoices

La Fattura La Fattura is a system designed for companies and individuals of all sizes to manage invoices, it integrates with Stripe for payments and w

Library to parse, format and convert byte units

Byte Units This is a utility component for parsing, formatting, converting and manipulating byte units in various formats. Usage ?php // Bytes manip

A library for handling physical quantities and the units of measure in which they're represented.

PHP Units of Measure master: Introduction This is a PHP library for representing and converting physical units of measure. The utility of this library

ColorJizz is a PHP library for manipulating and converting colors.

#Getting started: ColorJizz-PHP uses the PSR-0 standards for namespaces, so there should be no trouble using with frameworks like Symfony 2. ###Autolo

Collection of value objects that represent the PHP code units

sebastian/code-unit Collection of value objects that represent the PHP code units. Installation You can add this library as a local, per-project depen

Php library for converting emoji shortcodes to emoji

Emojify provides methods for checking if string is shortcode replace shortcode with emoji replacing all shortcodes in string with emoji Made for a md

A class to help convert bytes into other units (kb, mb, etc).

A class to help convert bytes into other units (kb, mb, etc). This package can be used to convert int|float values from bytes to KB, MB and GB as well

PHP Japanese string helper functions for converting Japanese strings from full-width to half-width and reverse. Laravel Rule for validation Japanese string only full-width or only half-width.

Japanese String Helpers PHP Japanese string helper functions for converting Japanese strings from full-width to half-width and reverse. Laravel Rule f

A PHP wrapper around Libreoffice for converting documents from one format to another.

Document Converter A PHP wrapper around Libreoffice for converting documents from one format to another. For example: Microsoft Word to PDF OpenOffice

Simple solution for converting excel rows into coordinates using Google Maps API

Package Usage Start by creating a new instance of ExcelToCoorindates class: $excel_to_cordinates = new ExcelToCoordinates(); Methods -setEx

PocketMine-MP Plugin for converting items & blocks name to your language.
PocketMine-MP Plugin for converting items & blocks name to your language.

ConvertName PocketMine-MP Plugin for converting items & blocks name to your language. Usage Due to license issue, I don't put the language files direc

Http-kernel - The HttpKernel component provides a structured process for converting a Request into a Response.

HttpKernel Component The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatc

laminas-xml2json provides functionality for converting XML structures to JSON

laminas-xml2json This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Stee

PHP Exif Library - library for reading and writing Exif headers in JPEG and TIFF files using PHP.

PEL: PHP Exif Library README file for PEL: PHP Exif Library. A library with support for reading and writing Exif headers in JPEG and TIFF images using

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

Comments
  • Currency

    Currency

    • Added currency converter
    • Added more tests, and made 100% code coverage
    • Removed toNativeUnit() as this didn't was used at all
    • Updated codeception to version 2 (meaning some namespace changes and generated a new build file)
    • Travis test for 5.5 and 5.6
    • Added adult shoesizes for EUR and UK
    opened by lsv 7
  • Bugfix: Acres conversion factor

    Bugfix: Acres conversion factor

    Hi guys,

    Found a bug in area units conversion. Current acres to meters conversion factor is invalid. Here is a wikipedia link with correct one: https://en.wikipedia.org/wiki/Acre#Equivalence_to_other_units_of_area

    It should be 4046.8564224 instead of 247.105. Would you be so kind to accept my PR?

    With Best Regards, Alexey Petrov

    opened by alexhelkar 1
  • Autoupdate packagist

    Autoupdate packagist

    ping @crisu83 I just tagged a new release and packagist did not show the new release. Seems like autoupdate is not enabled. Can you enable it in packagist.org?

    opened by ojhaujjwal 1
  • digital information: support for base number

    digital information: support for base number

    Is there support planned for distinguishing 1024 or 1000 based units? https://en.wikipedia.org/wiki/Mebibyte

    1 MB = 1000 kB 1 MiB = 1024 KiB

    As I see it, it can be done by simply adding these units to the "DigitalInformation" conversion map. Maybe create a separate Unit "SiDigitalInformation" to avoid confusion and allow users to keep using the old units as 1024-based.

    opened by rauwebieten 0
Releases(0.5.2)
Owner
Christoffer Niska
Technical Lead at @sightful, father of many, polyglot programmer, open source enthusiast, JavaScript Ninja.
Christoffer Niska
Library to parse, format and convert byte units

Byte Units This is a utility component for parsing, formatting, converting and manipulating byte units in various formats. Usage <?php // Bytes manip

Gabriele Lana 156 Dec 9, 2022
A library for handling physical quantities and the units of measure in which they're represented.

PHP Units of Measure master: Introduction This is a PHP library for representing and converting physical units of measure. The utility of this library

Jonathan Hanson 21 Sep 28, 2022
Mark Rogoyski 2.2k Dec 29, 2022
Tensor is a library and extension that provides objects for scientific computing in PHP.

Tensor is a library and extension that provides objects for scientific computing in PHP. The multithreaded extension is especially suited for computing large sets of numbers. In some cases, the extension is 230X faster than the same operation in PHPland. Tensor is used by libraries such as Rubix ML to build and accelerate machine learning algorithms such as linear regression, dimensionality reduction, and neural networks.

Rubix 157 Jan 3, 2023
PHP version of Google's phone number handling library

libphonenumber for PHP What is it? A PHP library for parsing, formatting, storing and validating international phone numbers. This library is based on

Joshua Gigg 4.2k Jan 7, 2023
A PHP 5.3+ mathematics library, providing functionality for large numbers

Moontoast Math Library Moontoast\Math is useful for working with integers that are larger than (or may become larger than, through mathematical comput

Moontoast 245 Sep 8, 2022
Advanced Mathematics Library for PHP (port of Numbers.js)

Numbers.php Numbers.php - an advanced mathematics toolkit for PHP >= 5.3. It is a port of Numbers.js - same toolkit for JavaScript. There is a version

null 159 Jul 24, 2022
BigNum library for PHP compatible with bn.js

BigNum library for PHP Information This library provides a PHP Big Number API compatible with bn.js and is used in Fast PHP ECC library elliptic-php.

Simplito 16 Nov 13, 2022
Arbitrary-precision arithmetic library for PHP

Arbitrary-precision arithmetic library for PHP

Brick 1.4k Jan 1, 2023
Unit converter and calculator for php

Unit converter and calculator This library uses the awesome lisachenko/z-engine to allow mathematical operations on objects, allowing to do stuff like

Dominik Chrástecký 8 Apr 8, 2022