PHPackages                             matriphe/format - 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. matriphe/format

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

matriphe/format
===============

Helpers contains common formatting, such as number, bytes, and phone.

2.2(7y ago)812.8k6[4 issues](https://github.com/matriphe/format/issues)[1 PRs](https://github.com/matriphe/format/pulls)1MITPHPPHP &gt;=7.0

Since Jan 31Pushed 5y agoCompare

[ Source](https://github.com/matriphe/format)[ Packagist](https://packagist.org/packages/matriphe/format)[ RSS](/packages/matriphe-format/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (7)Versions (16)Used By (1)

Format
======

[](#format)

[![Build Status](https://camo.githubusercontent.com/d24e44e9d14beb05fd651ecdca90514fc28dc81be8cd89b1f10e74f5c84c5ff0/68747470733a2f2f7472617669732d63692e6f72672f6d617472697068652f666f726d61742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/matriphe/format)[![Latest Stable Version](https://camo.githubusercontent.com/a8ef9d5fcbdbc4ba362efa47cd2c42fbe08c0b8cb9ad5cf04cac366861ff5057/68747470733a2f2f706f7365722e707567782e6f72672f6d617472697068652f666f726d61742f762f737461626c652e737667)](https://packagist.org/packages/matriphe/format)[![Total Downloads](https://camo.githubusercontent.com/b77a0ef49b10e667c1c200008e81c130bfe77ce04f59b6a38a02ca3018a8fe68/68747470733a2f2f706f7365722e707567782e6f72672f6d617472697068652f666f726d61742f646f776e6c6f6164732e737667)](https://packagist.org/packages/matriphe/format)[![License](https://camo.githubusercontent.com/543b6c9ea37f6726837d30b07702071390bee9a77a56103426f701097a893ae8/68747470733a2f2f706f7365722e707567782e6f72672f6d617472697068652f666f726d61742f6c6963656e73652e737667)](https://packagist.org/packages/matriphe/format)

Helpers contains common formatting, such as number, bytes, currency, phone, hash slug, format duration, and remove new line in string. Very handy for formatting things in Laravel.

Under the hood, it wraps some other great packages.

- [Laravel Intl](https://github.com/Propaganistas/Laravel-Intl)
- [Laravel Phone](https://github.com/Propaganistas/Laravel-Phone)
- [Byte Units](https://github.com/gabrielelana/byte-units)
- [Hashids](https://github.com/ivanakimov/hashids.php)

Compatibility
-------------

[](#compatibility)

This latest 2.0 version works with Laravel &gt;= 5.5. For previous version, [check 1.6 version](https://github.com/matriphe/format/tree/1.6).

It requires PHP &gt;= 7.0 and and bcmath extension.

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

[](#installation)

Open `composer.json` and require this line below.

```
"matriphe/format": "^2.0"
```

Or you can run this command from your project directory.

```
composer require matriphe/format
```

It used Laravel auto package discovery feature.

Usage
-----

[](#usage)

It's really easy to use the functions, by calling the `Format` facade or simply using global functions helpers.

It use internal locale, if you want to change the locale at runtime, just pass a `$locale` in the function.

On this example, we use Indonesia (id) locale as default.

### Format Number

[](#format-number)

```
// Using facade
// string Format::number(float $number, int $precision = 0, string $locale = null)
Format::number(1000); // output: '1.000'
Format::number(123456.76, 1); // output: '123.456,8'
Format::number(123456.76, 1, 'en'); // output: '123,456.8'

// Using global function
// string format_number(float $number, int $precision = 0, string $locale = null)
format_number(1000); // output: '1.000'
format_number(123456.76, 1); // output: '123.456,8'
format_number(123456.76, 1, 'en'); // output: '123,456.8'
```

### Format Currency

[](#format-currency)

```
// Using facade
// string Format::number(float $number, int $precision = 0, string $locale = null)
Format::currency(1000); // output: 'Rp1.000'
Format::currency(123456.76); // output: 'Rp123.457'
Format::currency(123456.76, 'us'); // output: 'US$123.456,76'

// Using global function
// string format_number(float $number, int $precision = 0, string $locale = null)
format_currency(1000); // output: 'Rp1.000'
format_currency(123456.76,); // output: 'Rp123.457'
format_currency(123456.76, 'us'); // output: 'US$123.456,76'
```

### Format Bytes

[](#format-bytes)

```
// Using facade
// string Format::bytes(float $number, int $precision = 1)
Format::bytes(100); // output: '100 B'
Format::bytes(1000); // output: '1 kB'
Format::bytes(2000000000, 0); // output: '2 GB'

// Using global function
// string format_bytes(float $number, int $precision = 1)
format_bytes(100); // output: '100 B'
format_bytes(1000); // output: '1 kB'
format_bytes(2000000000, 0); // output: '2 GB'
```

### Format to Bytes

[](#format-to-bytes)

```
// Using facade
// int Format::toBytes(string $stringBytes)
Format::toBytes('10k'); // output: 10240
Format::toBytes('10 M'); // output: 10485760
Format::toBytes('10G'); // output: 10737418240

// Using global function
// int format_to_bytes(string $stringBytes)
format_to_bytes('10k'); // output: 10240
format_to_bytes('10 M'); // output: 10485760
format_to_bytes('10G'); // output: 10737418240
```

### Format Phone

[](#format-phone)

```
// Using facade
// string Format::phone(string $phone, string $country = null)
Format::phone('085786920412'); // output: +6285786920412
Format::phone('+6285786920412'); // output: +6285786920412
Format::phone('(0274) 513-339'); // output: +62274513339
Format::phone('(65) 6655 4433', 'sg'); // output: +6566554433

// Using global function
// string format_phone(string $phone, string $country = null)
format_phone('085786920412'); // output: +6285786920412
format_phone('+6285786920412'); // output: +6285786920412
format_phone('(0274) 513-339'); // output: +62274513339
format_phone('(65) 6655 4433', 'sg'); // output: +6566554433
```

### Format Phone Human

[](#format-phone-human)

```
// Using facade
// string Format::phoneHuman(string $phone, string $country = null)
Format::phoneHuman('085786920412'); // output: 0857-8692-0412
Format::phoneHuman('+6285786920412'); // output: 0857-8692-0412
Format::phoneHuman('(0274) 513-339'); // output: (0274) 513339
Format::phoneHuman('+62274513339'); // output: (0274) 513339
Format::phoneHuman('(65) 6655 4433', 'sg'); // output: 6655 4433
Format::phoneHuman('+6566554433', 'sg'); // output: 6655 4433

// Using global function
// string format_phone_human(string $phone, string $country = null)
format_phone_human('085786920412'); // output: 0857-8692-0412
format_phone_human('+6285786920412'); // output: 0857-8692-0412
format_phone_human('(0274) 513-339'); // output: (0274) 513339
format_phone_human('+62274513339'); // output: (0274) 513339
format_phone_human('(65) 6655 4433', 'sg'); // output: 6655 4433
format_phone_human('+6566554433', 'sg'); // output: 6655 4433
```

### Format Phone Carrier

[](#format-phone-carrier)

```
// Using facade
// string Format::carrier(string $phone, string $country = null)
Format::carrier('085786920412'); // output: IM3
Format::carrier('+6281286920412'); // output: Telkomsel

// Using global function
// string format_carrier(string $phone, string $country = null)
format_carrier('085786920412'); // output: IM3
format_carrier('+6281286920412'); // output: Telkomsel
```

### Format DateRange

[](#format-daterange)

```
// Using facade
// string Format::dateRange(string $date1, string $date2 = null, bool $long = true, string $locale = null)
Format::dateRange('2015-03-03'); // output: 3 March 2015
Format::dateRange('2015-03-03', null, true, 'fr'); // output: 3 mars 2015
Format::dateRange('2015-03-03', null, false); // output: 3 Mar 15
Format::dateRange('2015-03-03', null, false, 'fr'); // output: 3 mar 15
Format::dateRange('2015-03-03', '2015-03-03'); // output: 3 March 2015
Format::dateRange('2015-03-03', '2015-03-03', false); // output: 3 Mar 15
Format::dateRange('2015-03-03', '2015-03-05'); // output: 3-5 March 2015
Format::dateRange('2015-03-03', '2015-03-05', true, 'fr'); // output: 3-5 mars 2015
Format::dateRange('2015-03-03', '2015-03-05', false); // output: 3-5 Mar 15
Format::dateRange('2015-03-03', '2015-03-05', false, 'fr'); // output: 3-5 mar 15
Format::dateRange('2015-03-03', '2015-04-05'); // output: 3 March - 5 April 2015
Format::dateRange('2015-03-03', '2015-04-05', true, 'fr'); // output: 3 mars - 5 avril 2015
Format::dateRange('2015-03-03', '2015-04-05', false); // output: 3 Mar - 5 Apr 15
Format::dateRange('2015-03-03', '2015-04-05', false, 'fr'); // output: 3 mar - 5 avr 15
Format::dateRange('2015-03-03', '2016-04-05'); // output: 3 March 2015 - 5 April 2016
Format::dateRange('2015-03-03', '2016-04-05', false); // output: 3 Mar 15 - 5 Apr 16

// Using global function
// string format_date_range(string $date1, string $date2 = null, bool $long = true, string $locale = null)
format_date_range('2015-03-03'); // output: 3 March 2015
format_date_range('2015-03-03', null, true, 'fr'); // output: 3 mars 2015
format_date_range('2015-03-03', null, false); // output: 3 Mar 15
format_date_range('2015-03-03', null, false, 'fr'); // output: 3 mar 15
format_date_range('2015-03-03', '2015-03-03'); // output: 3 March 2015
format_date_range('2015-03-03', '2015-03-03', false); // output: 3 Mar 15
format_date_range('2015-03-03', '2015-03-05'); // output: 3-5 March 2015
format_date_range('2015-03-03', '2015-03-05', true, 'fr'); // output: 3-5 mars 2015
format_date_range('2015-03-03', '2015-03-05', false); // output: 3-5 Mar 15
format_date_range('2015-03-03', '2015-03-05', false, 'fr'); // output: 3-5 mar 15
format_date_range('2015-03-03', '2015-04-05'); // output: 3 March - 5 April 2015
format_date_range('2015-03-03', '2015-04-05', true, 'fr'); // output: 3 mars - 5 avril 2015
format_date_range('2015-03-03', '2015-04-05', false); // output: 3 Mar - 5 Apr 15
format_date_range('2015-03-03', '2015-04-05', false, 'fr'); // output: 3 mar - 5 avr 15
format_date_range('2015-03-03', '2016-04-05'); // output: 3 March 2015 - 5 April 2016
format_date_range('2015-03-03', '2016-04-05', false); // output: 3 Mar 15 - 5 Apr 16
```

### Format Hashed Slug

[](#format-hashed-slug)

It's very useful to generate *hashed* URL slug like in URL shortener service. It use UNIX timestamp salt to generate unique ID. You can also set the length and the alphabet for the output.

```
// Using facade
// string Format::slugHash(int $id, $timestamp = null, string $alphabet = null, int $length = 6)
Format::slugHash(1); // output: 2qOPMd
Format::slugHash(2); // output: jbGm6-
Format::slugHash(3); // output: KMd9q5
Format::slugHash(1, '1984-03-22'); // output: adReK1
Format::slugHash(2, '1984-03-22'); // output: 9bqZ2g
Format::slugHash(3, '1984-03-22'); // output: EPaRND
Format::slugHash(1, '1984-03-22', '1234567890!@#$%^'); // output: $@76@8
Format::slugHash(2, '1984-03-22', '1234567890!@#$%^'); // output: 9%06%7
Format::slugHash(3, '1984-03-22', '1234567890!@#$%^'); // output: @9!%9!
Format::slugHash(1, '1984-03-22', '1234567890!@#$%^', 12); // output: %07$@76@8#6^
Format::slugHash(2, '1984-03-22', '1234567890!@#$%^', 12); // output: ^869%06%7$!0
Format::slugHash(3, '1984-03-22', '1234567890!@#$%^', 12); // output: ^#$@9!%9!067

// Using global function
// string format_slug_hash(int $id, $timestamp = null, string $alphabet = null, int $length = 6)
format_slug_hash(1); // output: 2qOPMd
format_slug_hash(2); // output: jbGm6-
format_slug_hash(3); // output: KMd9q5
format_slug_hash(1, '1984-03-22'); // output: adReK1
format_slug_hash(2, '1984-03-22'); // output: 9bqZ2g
format_slug_hash(3, '1984-03-22'); // output: EPaRND
format_slug_hash(1, '1984-03-22', '1234567890!@#$%^'); // output: $@76@8
format_slug_hash(2, '1984-03-22', '1234567890!@#$%^'); // output: 9%06%7
format_slug_hash(3, '1984-03-22', '1234567890!@#$%^'); // output: @9!%9!
format_slug_hash(1, '1984-03-22', '1234567890!@#$%^', 12); // output: %07$@76@8#6^
format_slug_hash(2, '1984-03-22', '1234567890!@#$%^', 12); // output: ^869%06%7$!0
format_slug_hash(3, '1984-03-22', '1234567890!@#$%^', 12); // output: ^#$@9!%9!067
```

#### Note for *hashed* slug

[](#note-for-hashed-slug)

If you want to save this hashed slug into MySQL, make sure the column is case sensitive. To do this, alter the column with this command.

```
ALTER TABLE `table` CHANGE `column_slug` `column_slug` VARCHAR(50) BINARY NOT NULL;
```

### Format Duration

[](#format-duration)

It's very useful to generate duration in days, hours, minutes, and seconds.

```
// Using facade
// string Format::duration(string $date1, string $date2, string $locale = null)
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:22:22'); // output: 1 hari
Format::duration('2015-05-15 11:22:22', '2015-05-17 11:22:22'); // output: 2 hari
Format::duration('2015-05-15 11:22:22', '2015-05-16 12:22:22'); // output: 1 hari 1 jam
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:22:22'); // output: 1 hari 2 jam
Format::duration('2015-05-15 11:22:22', '2015-05-17 12:22:22'); // output: 2 hari 1 jam
Format::duration('2015-05-15 11:22:22', '2015-05-17 13:22:22'); // output: 2 hari 2 jam
Format::duration('2015-05-15 11:22:22', '2015-05-16 12:23:22'); // output: 1 hari 1 jam 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-16 12:24:22'); // output: 1 hari 1 jam 2 menit
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:23:22'); // output: 1 hari 2 jam 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:23:22'); // output: 1 hari 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:24:22'); // output: 1 hari 2 menit
Format::duration('2015-05-15 11:22:22', '2015-05-17 11:24:22'); // output: 2 hari 2 menit
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:23:25'); // output: 1 hari 2 jam 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:22:25'); // output: 1 hari
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:23'); // output: 1 detik
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:27'); // output: 5 detik
Format::duration('2015-05-15 11:22:22', '2015-05-15 12:22:22'); // output: 1 jam
Format::duration('2015-05-15 11:22:22', '2015-05-15 13:22:22'); // output: 2 jam
Format::duration('2015-05-15 11:22:22', '2015-05-15 12:23:22'); // output: 1 jam 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 12:23:26'); // output: 1 jam 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 13:23:59'); // output: 2 jam 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:23:22'); // output: 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:24:22'); // output: 2 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:24:46'); // output: 2 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:24:46', true); // output: 2 menit 24 detik
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:23:22', true); // output: 1 menit
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:23', true); // output: 1 detik
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:27', true); // output: 5 detik
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:23:25', true); // output: 1 hari 2 jam 1 menit 3 detik
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:22:25', true); // output: 1 hari 3 detik

Format::duration('2015-05-15 11:22:22', '2015-05-16 11:22:22', 'en'); // output: 1 day
Format::duration('2015-05-15 11:22:22', '2015-05-17 11:22:22', 'en'); // output: 2 days
Format::duration('2015-05-15 11:22:22', '2015-05-16 12:22:22', 'en'); // output: 1 day 1 hour
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:22:22', 'en'); // output: 1 day 2 hours
Format::duration('2015-05-15 11:22:22', '2015-05-17 12:22:22', 'en'); // output: 2 days 1 hour
Format::duration('2015-05-15 11:22:22', '2015-05-17 13:22:22', 'en'); // output: 2 days 2 hours
Format::duration('2015-05-15 11:22:22', '2015-05-16 12:23:22', 'en'); // output: 1 day 1 hour 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-16 12:24:22', 'en'); // output: 1 day 1 hour 2 minutes
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:23:22', 'en'); // output: 1 day 2 hours 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:23:22', 'en'); // output: 1 day 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:24:22', 'en'); // output: 1 day 2 minutes
Format::duration('2015-05-15 11:22:22', '2015-05-17 11:24:22', 'en'); // output: 2 days 2 minutes
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:23:25', 'en'); // output: 1 day 2 hours 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:22:25', 'en'); // output: 1 day
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:23', 'en'); // output: 1 second
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:27', 'en'); // output: 5 seconds
Format::duration('2015-05-15 11:22:22', '2015-05-15 12:22:22', 'en'); // output: 1 hour
Format::duration('2015-05-15 11:22:22', '2015-05-15 13:22:22', 'en'); // output: 2 hours
Format::duration('2015-05-15 11:22:22', '2015-05-15 12:23:22', 'en'); // output: 1 hour 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-15 12:23:26', 'en'); // output: 1 hour 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-15 13:23:59', 'en'); // output: 2 hours 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:23:22', 'en'); // output: 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:24:22', 'en'); // output: 2 minutes
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:24:46', 'en'); // output: 2 minutes
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:24:46', 'en'); // output: 2 minutes 24 seconds
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:23:22', 'en'); // output: 1 minute
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:23', 'en'); // output: 1 second
Format::duration('2015-05-15 11:22:22', '2015-05-15 11:22:27', 'en'); // output: 5 seconds
Format::duration('2015-05-15 11:22:22', '2015-05-16 13:23:25', 'en'); // output: 1 day 2 hours 1 minute 3 seconds
Format::duration('2015-05-15 11:22:22', '2015-05-16 11:22:25', 'en'); // output: 1 day 3 seconds

// Using global function
// string format_duration(string $date1, string $date2, string $locale = null)
format_duration('2015-05-15 11:22:22', '2015-05-16 11:22:22'); // output: 1 hari
format_duration('2015-05-15 11:22:22', '2015-05-17 11:22:22'); // output: 2 hari
format_duration('2015-05-15 11:22:22', '2015-05-16 12:22:22'); // output: 1 hari 1 jam
format_duration('2015-05-15 11:22:22', '2015-05-16 13:22:22'); // output: 1 hari 2 jam
format_duration('2015-05-15 11:22:22', '2015-05-17 12:22:22'); // output: 2 hari 1 jam
format_duration('2015-05-15 11:22:22', '2015-05-17 13:22:22'); // output: 2 hari 2 jam
format_duration('2015-05-15 11:22:22', '2015-05-16 12:23:22'); // output: 1 hari 1 jam 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-16 12:24:22'); // output: 1 hari 1 jam 2 menit
format_duration('2015-05-15 11:22:22', '2015-05-16 13:23:22'); // output: 1 hari 2 jam 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-16 11:23:22'); // output: 1 hari 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-16 11:24:22'); // output: 1 hari 2 menit
format_duration('2015-05-15 11:22:22', '2015-05-17 11:24:22'); // output: 2 hari 2 menit
format_duration('2015-05-15 11:22:22', '2015-05-16 13:23:25'); // output: 1 hari 2 jam 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-16 11:22:25'); // output: 1 hari
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:23'); // output: 1 detik
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:27'); // output: 5 detik
format_duration('2015-05-15 11:22:22', '2015-05-15 12:22:22'); // output: 1 jam
format_duration('2015-05-15 11:22:22', '2015-05-15 13:22:22'); // output: 2 jam
format_duration('2015-05-15 11:22:22', '2015-05-15 12:23:22'); // output: 1 jam 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 12:23:26'); // output: 1 jam 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 13:23:59'); // output: 2 jam 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 11:23:22'); // output: 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 11:24:22'); // output: 2 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 11:24:46'); // output: 2 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 11:24:46', true); // output: 2 menit 24 detik
format_duration('2015-05-15 11:22:22', '2015-05-15 11:23:22', true); // output: 1 menit
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:23', true); // output: 1 detik
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:27', true); // output: 5 detik
format_duration('2015-05-15 11:22:22', '2015-05-16 13:23:25', true); // output: 1 hari 2 jam 1 menit 3 detik
format_duration('2015-05-15 11:22:22', '2015-05-16 11:22:25', true); // output: 1 hari 3 detik

format_duration('2015-05-15 11:22:22', '2015-05-16 11:22:22', 'en'); // output: 1 day
format_duration('2015-05-15 11:22:22', '2015-05-17 11:22:22', 'en'); // output: 2 days
format_duration('2015-05-15 11:22:22', '2015-05-16 12:22:22', 'en'); // output: 1 day 1 hour
format_duration('2015-05-15 11:22:22', '2015-05-16 13:22:22', 'en'); // output: 1 day 2 hours
format_duration('2015-05-15 11:22:22', '2015-05-17 12:22:22', 'en'); // output: 2 days 1 hour
format_duration('2015-05-15 11:22:22', '2015-05-17 13:22:22', 'en'); // output: 2 days 2 hours
format_duration('2015-05-15 11:22:22', '2015-05-16 12:23:22', 'en'); // output: 1 day 1 hour 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-16 12:24:22', 'en'); // output: 1 day 1 hour 2 minutes
format_duration('2015-05-15 11:22:22', '2015-05-16 13:23:22', 'en'); // output: 1 day 2 hours 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-16 11:23:22', 'en'); // output: 1 day 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-16 11:24:22', 'en'); // output: 1 day 2 minutes
format_duration('2015-05-15 11:22:22', '2015-05-17 11:24:22', 'en'); // output: 2 days 2 minutes
format_duration('2015-05-15 11:22:22', '2015-05-16 13:23:25', 'en'); // output: 1 day 2 hours 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-16 11:22:25', 'en'); // output: 1 day
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:23', 'en'); // output: 1 second
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:27', 'en'); // output: 5 seconds
format_duration('2015-05-15 11:22:22', '2015-05-15 12:22:22', 'en'); // output: 1 hour
format_duration('2015-05-15 11:22:22', '2015-05-15 13:22:22', 'en'); // output: 2 hours
format_duration('2015-05-15 11:22:22', '2015-05-15 12:23:22', 'en'); // output: 1 hour 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-15 12:23:26', 'en'); // output: 1 hour 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-15 13:23:59', 'en'); // output: 2 hours 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-15 11:23:22', 'en'); // output: 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-15 11:24:22', 'en'); // output: 2 minutes
format_duration('2015-05-15 11:22:22', '2015-05-15 11:24:46', 'en'); // output: 2 minutes
format_duration('2015-05-15 11:22:22', '2015-05-15 11:24:46', 'en'); // output: 2 minutes 24 seconds
format_duration('2015-05-15 11:22:22', '2015-05-15 11:23:22', 'en'); // output: 1 minute
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:23', 'en'); // output: 1 second
format_duration('2015-05-15 11:22:22', '2015-05-15 11:22:27', 'en'); // output: 5 seconds
format_duration('2015-05-15 11:22:22', '2015-05-16 13:23:25', 'en'); // output: 1 day 2 hours 1 minute 3 seconds
format_duration('2015-05-15 11:22:22', '2015-05-16 11:22:25', 'en'); // output: 1 day 3 seconds
```

### Remove New Line in String

[](#remove-new-line-in-string)

Will remove `\n`, `\r`, and spaces in string to make it in one line.

```
// Using facade
// string Format::removeNewLine(string $string)
Format::removeNewLine("Hello
        World"); // output: Hello World
Format::removeNewLine("Hello

        World

        "); // output: Hello World
Format::removeNewLine("Hello        World

        "); // output: Hello World

// Using global function
// string format_remove_new_line(string $string)
format_remove_new_line("Hello
        World"); // output: Hello World
format_remove_new_line("Hello

        World

        "); // output: Hello World
format_remove_new_line("Hello        World

        "); // output: Hello World
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% 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 ~101 days

Recently: every ~41 days

Total

14

Last Release

2855d ago

Major Versions

1.6.x-dev → 2.02018-07-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/809de97d088b0eff358f96141a31bd8897216a03175448192de140f2723bdea6?d=identicon)[matriphe](/maintainers/matriphe)

---

Top Contributors

[![matriphe](https://avatars.githubusercontent.com/u/277262?v=4)](https://github.com/matriphe "matriphe (25 commits)")[![parsingeye](https://avatars.githubusercontent.com/u/126904?v=4)](https://github.com/parsingeye "parsingeye (1 commits)")

---

Tags

laravelcurrencyhelpersphoneformatnumberbytes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/matriphe-format/health.svg)

```
[![Health](https://phpackages.com/badges/matriphe-format/health.svg)](https://phpackages.com/packages/matriphe-format)
```

###  Alternatives

[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7865.8M47](/packages/akaunting-laravel-money)[ysfkaya/filament-phone-input

A phone input component for Laravel Filament

3161.3M24](/packages/ysfkaya-filament-phone-input)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4375.4M23](/packages/kwn-number-to-words)[deligoez/laravel-model-hashid

Generate, Save, and Route Stripe/Youtube-like Hash IDs for Laravel Eloquent Models

166114.2k](/packages/deligoez-laravel-model-hashid)[dniccum/phone-number

A Laravel Nova phone number field with input masking and validation support.

70467.4k](/packages/dniccum-phone-number)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k18](/packages/solspace-craft-freeform)

PHPackages © 2026

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