PHPackages                             diversified-design/mesuraphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. diversified-design/mesuraphp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

diversified-design/mesuraphp
============================

Strongly-typed measurement units and conversions for PHP.

v0.3.1(3mo ago)29↓93.8%MITPHPPHP ^8.2

Since Feb 24Pushed 3mo agoCompare

[ Source](https://github.com/diversified-design/MesuraPHP)[ Packagist](https://packagist.org/packages/diversified-design/mesuraphp)[ RSS](/packages/diversified-design-mesuraphp/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (20)Versions (11)Used By (0)

MesuraPHP
=========

[](#mesuraphp)

A PHP library for representing, converting, and formatting physical measurements — from temperature and pressure to length, weight, and volume — with full SI metric prefix support and a fluent, type-safe API.

Installation
------------

[](#installation)

```
composer require diversified-design/mesura-php
```

Available Units
---------------

[](#available-units)

DomainAvailable unit**Angle****Degree**, Radian**Area**Acre, Hectare, SquareFoot, SquareKilometer, **SquareMeter**, SquareMile + all metric prefixes (see below)**ArealDensity**GramPerSquareMeter, **KilogramPerSquareMeter**, OuncePerSquareYard, PoundPerSquareFoot**Energy**BritishThermalUnit, Calorie, FootPound, **Joule**, Kilocalorie, KilowattHour, WattHour + all metric prefixes (see below)**Irradiance**BtuPerHourPerSquareFoot, KilowattPerSquareMeter, **WattPerSquareMeter****Length**Centimeter, Fathom, Foot, Furlong, HorseLength, Inch, Kilometer, **Meter**, Millimeter, NauticalMile, StatuteMile, SurveyMile, Thou, Yard + all metric prefixes (see below)**MassConcentration**GrainPerCubicFoot, GrainPerCubicMeter, GramPerCubicMeter, **KilogramPerCubicMeter**, MicrogramPerCubicMeter, MilligramPerCubicMeter**Percentage****Percent**, PartsPerMillion, PartsPerBillion**Power**BtuPerHour, CaloriePerSecond, FootPoundPerSecond, Horsepower, **Watt** + all metric prefixes (see below)**Pressure**Bar, Hectopascal, Kilopascal, Millibar, MillimetreOfMercury, **Pascal**, PoundPerSquareInch, StandardAtmosphere, Torr**SpecificEnergy**BtuPerPound, CaloriePerGram, **JoulePerKilogram**, KilojoulePerKilogram, MegajoulePerKilogram**Speed**KilometerPerHour, Knot, **MeterPerSecond**, MilesPerHour**Temperature**Celsius, Fahrenheit, **Kelvin**, Rankine**Time**Day, Hour, Minute, **Second****Torque****NewtonMeter****Volume**CubicInch, **CubicMeter**, CubicYard, FluidDram, FluidOunce, ImperialFluidDram, ImperialFluidOunce, ImperialPint, ImperialQuart, Liter, Pint, Quart, TableSpoon + all metric prefixes (see below)**Weight**Gram, **Kilogram**, MetricTon, Pound + all metric prefixes (see below)All the units of a domain can be converted to each other with corresponding methods.

### Full SI Metric Prefix Support

[](#full-si-metric-prefix-support)

Length, Weight, Volume (liters), Area (square meters), Energy (joules), and Power (watts) support all 24 SI metric prefixes — from Quetta (10^30) down to Quecto (10^-30). For example, Length includes Quettameter, Megameter, Kilometer, Centimeter, Nanometer, Quectometer, and everything in between. The same applies to the other metric dimensions (e.g. Milligram, Kiloliter, SquareCentimeter, Megajoule, Gigawatt).

Common prefixed units have dedicated convenience methods (e.g. `->toNanometer()`, `->toMilligram()`). All others are accessible via `->toUnit(Yottameter::class)`.

### Unit System Classification

[](#unit-system-classification)

Every unit exposes its measurement system via `unitSystem()`:

```
use Mesura\Length\Meter;
use Mesura\Temperature\Celsius;
use Mesura\Volume\Pint;

Meter::unitSystem();    // UnitSystem::SI
Celsius::unitSystem();  // UnitSystem::Metric
Pint::unitSystem();     // UnitSystem::USCustomary
```

Available systems: `SI`, `Metric`, `Imperial`, `USCustomary`, `Nautical`, `Dimensionless`, `Other`.

**See `./examples/unit_system.php` for filtering and grouping examples.**

---

Basic Usage
-----------

[](#basic-usage)

Set the value of the measurement unit directly

```
$celsius = new Celsius(28);
# $celsius = (Mesura\Temperature\Celsius) 28
```

Convert to another unit in the same domain:

```
$fahrenheit = $celsius->toFahrenheit();
# $fahrenheit = (Mesura\Temperature\Fahrenheit) 82.4
```

**See many more examples in `./examples/fluent_conversions.php` &amp; `./examples/complete_example.php`**

Fluent Usage
------------

[](#fluent-usage)

The same example as above, but fluently

```
$fahrenheit = (new Celsius(28))->toFahrenheit();
```

**See more examples in `./examples/fluent_conversions.php`**

Formatting output
-----------------

[](#formatting-output)

Formatting methods use [`sprintf()` ](https://www.php.net/manual/en/function.sprintf.php)

**See the examples in `./examples/formatting.php`**

Setting Custom Symbols
----------------------

[](#setting-custom-symbols)

All units have default symbols already assigned, but you can set custom ones per instance or per lifecycle.

**See the examples in `./examples/symbol_manipulation.php`**

You can also customize all units up-front in one go using the Customize class' `::unitSymbols()` static method.

**See the examples in `./examples/customize_units.php`**

---

Credit Due
==========

[](#credit-due)

This codebase is a much expanded and heavily modified "hard" fork of the excellent [PrinsFrank/measurement-unit](https://github.com/PrinsFrank/measurement-unit).

It adds several utility methods, many more units across more domains, and relies on [Brick\\Math](https://github.com/brick/math) for all conversions.

---

LLMs, Coding Agents, etc…
=========================

[](#llms-coding-agents-etc)

Yes, this work relies heavily on such tools. It is however not "vibe coded" nor "one-shotted."

As an artisan, I use the tools available *as tools*: to help me make better things, and learn faster.

Did I write every line of code? No. Do I understand every single part of it. No, but most of it.

I did (re)architect and (re)design it with my own knowledge, experience and needs, discussing with and instructing agents as I would have with a team of engineers.

**Issues and Pull Requests from fellow humans are always welcome.**

---

I hope you find this library as useful and pleasurable to use as I do.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance79

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

9

Last Release

110d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ddf207882d01304f332aacb1f3dd78b9b9a5f75f9a55a138e23d2bb75fc66201?d=identicon)[BorisAnthony](/maintainers/BorisAnthony)

---

Top Contributors

[![BorisAnthony](https://avatars.githubusercontent.com/u/964649?v=4)](https://github.com/BorisAnthony "BorisAnthony (78 commits)")

---

Tags

conversionspeedunitsweightmetrictemperatureareameasurementlengthpressurevolumeSIstrongly-typedimperialunit-conversion

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/diversified-design-mesuraphp/health.svg)

```
[![Health](https://phpackages.com/badges/diversified-design-mesuraphp/health.svg)](https://phpackages.com/packages/diversified-design-mesuraphp)
```

###  Alternatives

[jbzoo/simpletypes

The universal PHP library to convert any values and measures

621.8k1](/packages/jbzoo-simpletypes)[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k9.3M28](/packages/mjaschen-phpgeo)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k104](/packages/flow-php-etl)[cartalyst/converter

A framework agnostic measurement conversion and formatting package featuring multiple types of measurements and currency conversion.

91488.9k7](/packages/cartalyst-converter)[php-unit-conversion/php-unit-conversion

A fully PSR-4 compatible PHP library for converting between standard units of measure.

691.2M2](/packages/php-unit-conversion-php-unit-conversion)[nmarfurt/measurements

A PHP library for representing and converting dimensional units of measure.

17183.8k1](/packages/nmarfurt-measurements)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
