PHPackages                             victoryoalli/laravel-string-macros - 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. victoryoalli/laravel-string-macros

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

victoryoalli/laravel-string-macros
==================================

A set of useful Laravel string macros

v2.1.0(4mo ago)83.4k2[1 issues](https://github.com/victoryoalli/laravel-string-macros/issues)1MITPHPPHP ^8.2CI failing

Since Aug 15Pushed 4mo agoCompare

[ Source](https://github.com/victoryoalli/laravel-string-macros)[ Packagist](https://packagist.org/packages/victoryoalli/laravel-string-macros)[ Docs](https://github.com/victoryoalli/laravel-string-macros)[ Fund](https://victoryoalli.me/open-source/support-us)[ GitHub Sponsors](https://github.com/victoryoalli)[ RSS](/packages/victoryoalli-laravel-string-macros/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (16)Used By (1)

Laravel String Macros
=====================

[](#laravel-string-macros)

[![GitHub release (latest by date)](https://camo.githubusercontent.com/06cae1e937f253b82403fb68a74b45485ddd5e66c13df8ae60ed3d46440521fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f766963746f72796f616c6c692f6c61726176656c2d737472696e672d6d6163726f73)](https://camo.githubusercontent.com/06cae1e937f253b82403fb68a74b45485ddd5e66c13df8ae60ed3d46440521fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f766963746f72796f616c6c692f6c61726176656c2d737472696e672d6d6163726f73)[![Packagist Downloads](https://camo.githubusercontent.com/c3fe15cbfb2eca987d57b8211c84494119c9f9dec3097217875953b24ee4abe5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963746f72796f616c6c692f6c61726176656c2d737472696e672d6d6163726f73)](https://camo.githubusercontent.com/c3fe15cbfb2eca987d57b8211c84494119c9f9dec3097217875953b24ee4abe5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963746f72796f616c6c692f6c61726176656c2d737472696e672d6d6163726f73)

A collection of useful string macros for Laravel's `Str` and `Stringable` classes.

Requirements
------------

[](#requirements)

VersionPHPLaravel2.1+^8.210.x, 11.x, 12.x2.0^8.110.x, 11.x1.x^8.08.x, 9.x, 10.xInstallation
------------

[](#installation)

```
composer require victoryoalli/laravel-string-macros
```

Available Macros
----------------

[](#available-macros)

All macros are available both as static methods on `Str` and as fluent methods on `Stringable`.

### initials

[](#initials)

Gets the initials of the words you provide. Defaults to 2 initials.

```
use Illuminate\Support\Str;

// Static usage
Str::initials('Victor Yoalli Dominguez');
// "VY"

Str::initials('Victor Yoalli Dominguez', 3);
// "VYD"

// Fluent usage
Str::of('Victor Yoalli Dominguez')->initials()->toString();
// "VY"

Str::of('Victor Yoalli Dominguez')->initials(3)->upper()->toString();
// "VYD"
```

**Note:** Words are split by spaces, commas, underscores, and hyphens. For example, `Jean-Pierre` is treated as two words.

### interpolate

[](#interpolate)

Replaces `?` placeholders with the values you provide.

```
use Illuminate\Support\Str;

// Static usage - multiple arguments
Str::interpolate('Roses are ? Violets are ?', 'RED', 'BLUE');
// "Roses are RED Violets are BLUE"

// Static usage - array
Str::interpolate('Roses are ? Violets are ?', ['RED', 'BLUE']);
// "Roses are RED Violets are BLUE"

// Static usage - spread operator
Str::interpolate('Roses are ? Violets are ?', ...['RED', 'BLUE']);
// "Roses are RED Violets are BLUE"

// Fluent usage
Str::of('Hello ? and ?')->interpolate(['World', 'Universe'])->toString();
// "Hello World and Universe"
```

### readingMinutes

[](#readingminutes)

Calculates how many minutes it takes to read the text. Accepts HTML (tags are stripped for accurate calculation). Default reading speed is 200 words per minute.

```
use Illuminate\Support\Str;

// Static usage
Str::readingMinutes('Your long article text here...');
// 1

// With custom words per minute
Str::readingMinutes($longText, 150);
// 3

// Fluent usage
Str::of('HTML content')->readingMinutes()->toString();
// "1"
```

### linesCount

[](#linescount)

Counts the number of lines in a string (splits by `\n` or `\r`).

```
use Illuminate\Support\Str;

// Static usage
Str::linesCount("Line 1\nLine 2\nLine 3");
// 3

// Fluent usage
Str::of("Hello\nWorld")->linesCount()->toString();
// "2"
```

Fluent Chaining
---------------

[](#fluent-chaining)

All macros can be chained with other `Stringable` methods:

```
use Illuminate\Support\Str;

$result = Str::of('? ? ?')
    ->interpolate(['Victor', 'Yoalli', 'Dominguez'])
    ->initials(3)
    ->upper()
    ->toString();
// "VYD"
```

---

Upgrading from v1.x to v2.x
---------------------------

[](#upgrading-from-v1x-to-v2x)

### Breaking Changes

[](#breaking-changes)

#### Removed Macros

[](#removed-macros)

The following macros have been **removed** because they are now available natively in Laravel 10+:

Removed MacroUse InsteadAvailable Since`Str::human($value)``Str::headline($value)`Laravel 9.x`Str::matches($pattern, $value)``Str::isMatch($pattern, $value)`Laravel 10.x#### Migration Examples

[](#migration-examples)

**Before (v1.x):**

```
// human() - converts to human readable format
Str::human('hello_world');  // "hello world"
Str::of('hello_world')->human();

// matches() - check if string matches regex
Str::matches('/^hello/', 'hello world');  // true
Str::of('hello world')->matches('/^hello/');
```

**After (v2.x) - Use Laravel native methods:**

```
// headline() - converts to title case with spaces
Str::headline('hello_world');  // "Hello World"
Str::of('hello_world')->headline();

// isMatch() - check if string matches regex
Str::isMatch('/^hello/', 'hello world');  // true
Str::of('hello world')->isMatch('/^hello/');
```

**Note:** `Str::headline()` capitalizes each word, while the old `Str::human()` did not. If you need lowercase output, chain with `->lower()`:

```
Str::of('hello_world')->headline()->lower()->toString();
// "hello world"
```

#### PHP and Laravel Version Requirements

[](#php-and-laravel-version-requirements)

Requirementv1.xv2.0v2.1+PHP^8.0^8.1^8.2Laravel8.x, 9.x, 10.x10.x, 11.x10.x, 11.x, 12.x### Upgrade Steps

[](#upgrade-steps)

1. **Update your `composer.json`** or run:

    ```
    composer require victoryoalli/laravel-string-macros:^2.0
    ```
2. **Search and replace** removed macros in your codebase:

    ```
    # Find usages of removed macros
    grep -r "Str::human\|->human(" app/
    grep -r "Str::matches\|->matches(" app/
    ```
3. **Replace with native Laravel methods:**

    - `Str::human()` → `Str::headline()`
    - `Str::matches()` → `Str::isMatch()`
    - `->human()` → `->headline()`
    - `->matches()` → `->isMatch()`
4. **Run your tests** to ensure everything works correctly.

---

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Victor Yoalli](https://github.com/victoryoalli)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance72

Regular maintenance activity

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity75

Established project with proven stability

 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 ~140 days

Recently: every ~255 days

Total

15

Last Release

142d ago

Major Versions

0.4.0 → 1.0.02023-03-14

1.0.1 → v2.0.02025-12-28

PHP version history (6 changes)0.1.0PHP ^7.4

0.2.0PHP ^7.4|^8.0

0.3.0PHP ^8.0.2

1.0.0PHP ^8.0

v2.0.0PHP ^8.1

v2.1.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/488202a656e6be4d5992b6c2d7bb91155587fa7144279b5c52f671b5d88eb24e?d=identicon)[victoryoalli](/maintainers/victoryoalli)

---

Top Contributors

[![victoryoalli](https://avatars.githubusercontent.com/u/141497?v=4)](https://github.com/victoryoalli "victoryoalli (29 commits)")

---

Tags

victoryoallilaravel-string-macros

### Embed Badge

![Health badge](/badges/victoryoalli-laravel-string-macros/health.svg)

```
[![Health](https://phpackages.com/badges/victoryoalli-laravel-string-macros/health.svg)](https://phpackages.com/packages/victoryoalli-laravel-string-macros)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[illuminate/cookie

The Illuminate Cookie package.

224.3M122](/packages/illuminate-cookie)

PHPackages © 2026

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