xxzeroxx / unit-converter
PHP library for converting units.
v2.0.0
2026-04-26 22:49 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.6
README
UnitConverter is a simple and robust PHP library for converting units of measurement. It supports conversions between lengths, masses, volumes, temperatures and areas. Useful in scientific and educational applications, or any project that requires the manipulation of units.
🚀 Features
- Length conversion (mm, cm, m, km)
- Mass conversion (g, kg, t)
- Volume conversion (ml, l, m³)
- Temperature conversion (C, F, K)
- Area conversion (m², cm², km²)
- Simple and intuitive API
- Lightweight and dependency-free
- Fully tested with PHPUnit
- PHP 8+ support
⚠️ Breaking Changes (v2.0.0)
- Dropped support for PHP 7.x
- Minimum required PHP version is now 8.0
📦 Installation
Install via Composer:
composer require xxzeroxx/unit-converter
📖 Usage
require 'vendor/autoload.php'; use UnitConverter\UnitConverter; $converter = new UnitConverter(); // Length echo $converter->convertLength(1, 'km', 'm'); // 1000 // Mass echo $converter->convertMass(1000, 'g', 'kg'); // 1 // Volume echo $converter->convertVolume(1, 'm³', 'l'); // 1000 // Temperature echo $converter->convertTemperature(0, 'C', 'F'); // 32 // Area echo $converter->convertArea(1, 'm²', 'cm²'); // 10000
❗ Error Handling
The library throws exceptions for invalid units:
$converter->convertLength(10, 'invalid', 'm');
🧪 Running Tests
composer test
📜 Changelog
See CHANGELOG.md for version history.
🤝 Contributing
Contributions are welcome!
- Fork the project
- Create your feature branch
- Commit your changes
- Push to your branch
- Open a Pull Request
📄 License
This project is licensed under the MIT License.