PHPackages                             ramazancetinkaya/byte-formatter - 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. ramazancetinkaya/byte-formatter

ActiveLibrary

ramazancetinkaya/byte-formatter
===============================

A modern PHP library for formatting and parsing byte values with precision and flexibility.

1.0.0(1y ago)144.0k↓17.4%2MITPHPPHP &gt;=8.0

Since Dec 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ramazancetinkaya/byte-formatter)[ Packagist](https://packagist.org/packages/ramazancetinkaya/byte-formatter)[ Docs](https://github.com/ramazancetinkaya/byte-formatter)[ RSS](/packages/ramazancetinkaya-byte-formatter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Byte Formatter Library
======================

[](#byte-formatter-library)

[![PHP Version](https://camo.githubusercontent.com/14639c17ca36d5516bab07357840361ab57c5258fb0f110ae9cefb75611b59b3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d3737376262343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/14639c17ca36d5516bab07357840361ab57c5258fb0f110ae9cefb75611b59b3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d3737376262343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)[![Packagist](https://camo.githubusercontent.com/40df0191a9787cb2b8fe570fa6c4b75b03e6a1ed6fc0bcf3f505b14d0c965101/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616d617a616e636574696e6b6179612f627974652d666f726d61747465723f7374796c653d666f722d7468652d626164676526636f6c6f723d333443373539)](https://packagist.org/packages/ramazancetinkaya/byte-formatter)[![Downloads](https://camo.githubusercontent.com/3525a00154ca618b4ed76433a95561dc0a89398ba07306fe0f384361e478804d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616d617a616e636574696e6b6179612f627974652d666f726d61747465723f7374796c653d666f722d7468652d626164676526636f6c6f723d6f72616e6765)](https://camo.githubusercontent.com/3525a00154ca618b4ed76433a95561dc0a89398ba07306fe0f384361e478804d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616d617a616e636574696e6b6179612f627974652d666f726d61747465723f7374796c653d666f722d7468652d626164676526636f6c6f723d6f72616e6765)[![License](https://camo.githubusercontent.com/4ee85824611af0644848637137fbd9c74da9b617f54ab2415cd519bb539a60bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d6f70656e2d736f757263652d696e6974696174697665266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/4ee85824611af0644848637137fbd9c74da9b617f54ab2415cd519bb539a60bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d6f70656e2d736f757263652d696e6974696174697665266c6f676f436f6c6f723d7768697465)[![Stars](https://camo.githubusercontent.com/90ee98e49ae21d65878747f0f1e51febde7b96e1d5fd2e0731aaf7b43e7b8d5d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f72616d617a616e636574696e6b6179612f627974652d666f726d61747465723f7374796c653d666f722d7468652d626164676526636f6c6f723d464144303245266c6f676f3d676974687562)](https://github.com/ramazancetinkaya/byte-formatter/stargazers)[![Issues](https://camo.githubusercontent.com/4e81dd2622fd6f5876f5e52767a537fa2e5b901c8fd9e8a7d1b1bf6b6cdfe00f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f72616d617a616e636574696e6b6179612f627974652d666f726d61747465723f7374796c653d666f722d7468652d626164676526636f6c6f723d453434303546266c6f676f3d676974687562)](https://github.com/ramazancetinkaya/byte-formatter/issues)

**Byte Formatter** is your go-to PHP library for converting bytes into human-readable strings and vice versa. Built with modern PHP 8 features, it’s **fast**, **reliable**, and **developer-friendly**—making your life just that little bit easier when handling data sizes.

[Report a Bug](https://github.com/ramazancetinkaya/byte-formatter/issues)· [New Pull Request](https://github.com/ramazancetinkaya/byte-formatter/pulls)

### ⭐ Show Your Support

[](#-show-your-support)

If you like this project, give it a ⭐ and share it with your network!

---

🚀 Features
----------

[](#-features)

- 🧠 **Smart Formatting**: Converts bytes to formats like `10 KiB` or `10 KB`.
- 🔄 **Two-Way Conversion**: Parse size strings like `1.5 MB` into bytes.
- 🎛️ **Customizable Precision**: Fine-tune decimal places in formatted outputs.
- ⚙️ **Binary &amp; Decimal Prefixes**: Switch between 1024 (binary) and 1000 (decimal) systems.
- 💪 **Error Resilient**: Robust validation and descriptive error handling.
- 📦 **Lightweight &amp; Dependency-Free**: No external dependencies—just clean, reliable PHP.

📦 Installation
--------------

[](#-installation)

You can install the `ByteFormatter` library using [Composer](https://getcomposer.org/). Run the following command in your terminal:

```
composer require ramazancetinkaya/byte-formatter
```

Alternatively, download the source code and include it in your project manually.

### Requirements

[](#requirements)

- PHP 8.0 or higher.
- No additional dependencies.

📖 Usage Examples
----------------

[](#-usage-examples)

### 1. **Basic Formatting**

[](#1-basic-formatting)

```
require 'vendor/autoload.php';

use ramazancetinkaya\ByteFormatter;

$formatter = new ByteFormatter(true, 2); // Binary prefixes, 2 decimal places

echo $formatter->formatBytes(10240); // Output: "10 KiB"
```

### 2. **Parse Human-Readable Strings**

[](#2-parse-human-readable-strings)

```
require 'vendor/autoload.php';

use ramazancetinkaya\ByteFormatter;

$formatter = new ByteFormatter();

$bytes = $formatter->parseSize("1.5 MiB");

echo $bytes; // Output: 1572864
```

### 3. **Convert Byte Sizes Between Prefix Systems**

[](#3-convert-byte-sizes-between-prefix-systems)

```
require 'vendor/autoload.php';

use ramazancetinkaya\ByteFormatter;

$formatter = new ByteFormatter();

echo $formatter->convert(10240, false); // Output: "10 KB" (Decimal prefix)
```

⚙ Configuration
---------------

[](#-configuration)

OptionDescriptionDefault`useBinaryPrefix`Use binary prefixes (1024-based) or decimal (1000)`true``precision`Number of decimal places for formatted output`2`📖 Documentation
---------------

[](#-documentation)

### Public Methods

[](#public-methods)

MethodDescription`formatBytes()`Formats a byte size into a human-readable string.`parseSize()`Parses a human-readable size string into bytes.`convert()`Converts a size between binary and decimal prefix systems or to a specific unit.📂 **Project Structure**
-----------------------

[](#-project-structure)

```
src/
├── ByteFormatter.php
composer.json
README.md

```

🛡 Security
----------

[](#-security)

This library is designed with security in mind. Input validation and error handling are implemented to prevent misuse. For vulnerabilities, please [open an issue](https://github.com/ramazancetinkaya/byte-formatter/issues).

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

📄 License
---------

[](#-license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance40

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

505d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04d76b5f72582c06350c3e59cc86fd79990444480ee01ab119e770ce34b4c9a1?d=identicon)[ramazancetinkaya](/maintainers/ramazancetinkaya)

---

Tags

byte-formatterhuman-readable-formatshuman-readable-unitsphpphp8size-converterphpdecimalbinaryPHP Librarydata-formattingbyte-formattersize-conversion

### Embed Badge

![Health badge](/badges/ramazancetinkaya-byte-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/ramazancetinkaya-byte-formatter/health.svg)](https://phpackages.com/packages/ramazancetinkaya-byte-formatter)
```

PHPackages © 2026

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