ravjanisz/readablesize

dev-master 2019-10-22 18:26 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:10 UTC


README

Build Status codecov

将字节数转换为人类可读的数字,通过获取字节数将进入的该单位的数量。

要求

  • PHP >= 7.1
  • (可选) PHPUnit 运行测试。

安装

通过 Composer

$ composer require ravjanisz/readablesize

用法

// add settings instance
use Rav\Size\SizeSettings;
// add instance
use Rav\Size\Size;

//base for calculation can be added as SizeSettings constructor parameter
//SizeSettings::BINARY or SizeSettings::DECIMAL
$settings = new SizeSettings();
//set precision for size
$settings->setPrecision(2);

//new object instance
$this->size = new Size($settings);

//return '1.46KiB'
echo $this->size->human('1500');

//convert size
//return '0.01TiB'
echo $this->size->convert(Size::MB, Size::TB, '9500');

文档

支持开发

你喜欢这个项目吗?通过捐赠支持它

alt Buy me a coffee

许可证

readablesize 采用 MIT 许可证 - 请参阅 LICENSE 文件以获取详细信息