PHPackages                             mpstenson/laravel-advanced-string - 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. mpstenson/laravel-advanced-string

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

mpstenson/laravel-advanced-string
=================================

This application provides advanced string functions beyond what Laravel itself provides.

1.1.1(1y ago)725.7k↓50%6[3 PRs](https://github.com/mpstenson/laravel-advanced-string/pulls)MITPHPPHP ^8.2CI passing

Since Jul 11Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mpstenson/laravel-advanced-string)[ Packagist](https://packagist.org/packages/mpstenson/laravel-advanced-string)[ Docs](https://github.com/mpstenson/laravel-advanced-string)[ GitHub Sponsors]()[ RSS](/packages/mpstenson-laravel-advanced-string/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (12)Used By (0)

Laravel Advanced String Package
===============================

[](#laravel-advanced-string-package)

*Tested, community maintained, supercharged Laravel string functions.*

[![Latest Version on Packagist](https://camo.githubusercontent.com/b9a84d77fba082aabe2e0d843efcccfbeff5f9915e335536574d664ccd23cb25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d707374656e736f6e2f6c61726176656c2d616476616e6365642d737472696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mpstenson/laravel-advanced-string)[![GitHub Tests Action Status](https://camo.githubusercontent.com/946b5abdf13c89b11a258419b66aa1c77f1aa4b647574170e6294228ea894318/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d707374656e736f6e2f6c61726176656c2d616476616e6365642d737472696e672f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mpstenson/laravel-advanced-string/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/eb350b8949d77d7226fe2161f5e30bc64daac296b33b57bab14e0ecab8397dad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d707374656e736f6e2f6c61726176656c2d616476616e6365642d737472696e672f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/mpstenson/laravel-advanced-string/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/dc90606a6f9c4dfe7b3cf911c725cb7bde1017515772dd7c7c1f50e4215ea425/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d707374656e736f6e2f6c61726176656c2d616476616e6365642d737472696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mpstenson/laravel-advanced-string)

Laravel Advanced String is a Laravel package that adds advanced string manipulation methods to the built in `Str` class that Laravel provides. You get extended functionality on strings such as advanced password generation, data redaction, and more.

The Laravel Advanced String package by default adds macros to the `Str` class so your can access the extended functionality in the same class that your other string methods are found in. You can also disable this functionality the in the package config and use the `AdvStr` class directly.

### Example

[](#example)

    ssnRedaction-compressed.mp4    ```
Str::redactSsn('My social security number is 222-22-2222'); // My social security number is xxxxxx
```

OR...

```
AdvStr::redactSsn('My social security number is 222-22-2222'); // My social security number is xxxxxx
```

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Available Methods](#available-methods)
    - [advPassword](#advpassword)
    - [charWrap](#charwrap)
    - [emailDomain](#emaildomain)
    - [randomPhrase](#randomphrase)
    - [randomWord](#randomword)
    - [readTime](#readtime)
    - [redactCreditCard](#redactcreditcard)
    - [redactSsn](#redactssn)
    - [splitName](#splitname)
- [Testing](#testing)
- [Changelog](#changelog)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require mpstenson/laravel-advanced-string
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-advanced-string-config"
```

This is the contents of the published config file:

```
return [

    /*
    // Macro the AdvStr class to the Illuminate\Support\Str class. You can disable
    // this here if you don't want the AdvStr methods available on the Str class
    */

    'use_str' => true,

];
```

Usage
-----

[](#usage)

The Laravel Advanced String package by default adds macros to the `Str` class so your can access the extended functionality immediately

```
Str::redactSsn('123-45-6789')
```

Available Methods
-----------------

[](#available-methods)

### [advPassword](#advpassword)

[](#advpassword)

Generates a random, secure password.

```
public static function advPassword(
    $length = 32,
    $letters = true,
    $numbers = true,
    $symbols = true,
    $spaces = false,
    $upperLetters = false,
    $lowerLetters = false,
    $exclude = []
)
```

#### Parameters:

[](#parameters)

- `$length` (int): Length of the password (default: 32)
- `$letters` (bool): Include mixed case letters (default: true)
- `$numbers` (bool): Include numbers (default: true)
- `$symbols` (bool): Include symbols (default: true)
- `$spaces` (bool): Include spaces (default: false)
- `$upperLetters` (bool): Include uppercase letters (default: false)
- `$lowerLetters` (bool): Include lowercase letters (default: false)
- `$exclude` (array): Characters to exclude from the password

#### Returns:

[](#returns)

- string: Generated password

### [charWrap](#charwrap)

[](#charwrap)

Wraps a string at a given number of characters regardless of words.

```
public static function charWrap(
    $string,
    $length = 80
)
```

#### Parameters:

[](#parameters-1)

- `$string` (string): The string to wrap
- `$length` (int): The number of characters to wrap at (default: 80)

#### Returns:

[](#returns-1)

- string: The wrapped string

### [emailDomain](#emailDomain)

[](#emaildomain)

Extracts the domain part of an email address, including subdomains.

```
public static function emailDomain(
    $string
)
```

#### Parameters:

[](#parameters-2)

- `$string` (string): The string to extract the email domain from.

#### Returns:

[](#returns-2)

- string: The email domain from the string

### [randomPhrase](#randomphrase)

[](#randomphrase)

Returns a random phrase with a configurable delimiter.

```
public static function randomPhrase(
    $wordCount,
    $separator = '-'
)
```

#### Parameters:

[](#parameters-3)

- `$wordCount` (int): The number of words in the phrase.
- `$separator` (string): The separator between words (default: '-').

#### Returns:

[](#returns-3)

- string: The generated random phrase.

### [randomWord](#randomword)

[](#randomword)

Returns a random word.

```
public static function randomWord(
)
```

#### Parameters:

[](#parameters-4)

- none

#### Returns:

[](#returns-4)

- string: A random word

### [readTime](#readtime)

[](#readtime)

Calculates the read time of a string.

```
public static function readTime(
    $string,
    $wpm = 200
)
```

#### Parameters:

[](#parameters-5)

- `$string` (string): The text to calculate read time for
- `$wpm` (int): Words per minute (default: 200)

#### Returns:

[](#returns-5)

- float: Estimated read time in seconds

### [redactCreditCard](#redactcreditcard)

[](#redactcreditcard)

Redacts credit card numbers in a string.

```
public static function redactCreditCard(
    $string,
    $redacted = '********',
    $exclude = []
)
```

#### Parameters:

[](#parameters-6)

- `$string` (string): The string containing credit card numbers to redact
- `$redacted` (string): The string to replace credit card numbers with (default: '\*\*\*\*\*\*\*\*')
- `$exclude` (array): An array of credit card types to exclude from redaction. Possible types: 'mastercard','visa','amex','discover','diners','jcb'

#### Returns:

[](#returns-6)

- string: The string with credit card numbers redacted

### [redactSsn](#redactssn)

[](#redactssn)

Redacts Social Security Numbers (SSN) in a string.

```
public static function redactSsn(
    $string,
    $redacted = '********',
    $dashes = true,
    $noDashes = true
)
```

#### Parameters:

[](#parameters-7)

- `$string` (string): The string containing SSNs to redact
- `$redacted` (string): The string to replace SSNs with (default: '\*\*\*\*\*\*\*\*')
- `$dashes` (bool): Redact SSNs with dashes (default: true)
- `$noDashes` (bool): Redact SSNs without dashes (default: true)

#### Returns:

[](#returns-7)

- string: The string with SSNs redacted

### [splitName](#splitname)

[](#splitname)

Splits a full name into first name, middle name (if present), and last name, removing any prefixes and suffixes. This method can handle both "Firstname Lastname" and "Lastname, Firstname" formats.

```
public static function splitName(
    $name
)
```

#### Parameters:

[](#parameters-8)

- `$name` (string): The full name to split

#### Returns:

[](#returns-8)

- array: An associative array containing 'first', 'middle' (if present), and 'last' name

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Matt Stenson](https://github.com/mpstenson)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance69

Regular maintenance activity

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.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 ~40 days

Recently: every ~61 days

Total

7

Last Release

432d ago

Major Versions

0.0.3 → 1.0.02024-07-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9a1168f988720e92a8e4b0b70ee310c5bb6b50c6db65f58c12e61d044e8661a?d=identicon)[mpstenson](/maintainers/mpstenson)

---

Top Contributors

[![mpstenson](https://avatars.githubusercontent.com/u/1500588?v=4)](https://github.com/mpstenson "mpstenson (42 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")[![matthewpaulking](https://avatars.githubusercontent.com/u/32152670?v=4)](https://github.com/matthewpaulking "matthewpaulking (1 commits)")[![rtaylor82](https://avatars.githubusercontent.com/u/6969996?v=4)](https://github.com/rtaylor82 "rtaylor82 (1 commits)")

---

Tags

helperslaravellaravel-packagestring-manipulationlaravelMatt Stensonlaravel-advanced-string

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mpstenson-laravel-advanced-string/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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