PHPackages                             jkque/laravel-string-replace - 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. jkque/laravel-string-replace

ActiveLibrary

jkque/laravel-string-replace
============================

Helper for a messy str\_replace

1.0.0(5y ago)95.0k↓33.3%3MITPHPPHP ^7.1

Since Jul 5Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/jkque/laravel-string-replace)[ Packagist](https://packagist.org/packages/jkque/laravel-string-replace)[ Docs](https://github.com/jkque/laravel-string-replace)[ RSS](/packages/jkque-laravel-string-replace/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

For complex string replace
==========================

[](#for-complex-string-replace)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bf9a89339ac481e5447dd69c038d0d7d81bfe05740bb9c64da2fada768520086/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6b7175652f6c61726176656c2d737472696e672d7265706c6163652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jkque/laravel-string-replace)[![Total Downloads](https://camo.githubusercontent.com/b192fd7c95a269f512172373fb744ca9b030cb991843752d437c24eb65bbd7df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6b7175652f6c61726176656c2d737472696e672d7265706c6163652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jkque/laravel-string-replace)

This package will help you when [str\_replace](https://www.php.net/manual/en/function.str-replace.php) gets a little bit messy.

Introduction
------------

[](#introduction)

When you see something like this:

```
$remove_characters = ['', '', '&#39;', '&#039;', '', '', '', '', '&nbsp;', '&#63;','@name', '&rsquot;', '&quot;', '@firstname'];
$replace_with = ['', '', "'", "'", '', '', '', '', '', '?', $user->name, "'", '"', $user->first_name];

$message = str_replace($remove_characters, $replace_with, $message);
```

A cleaner way:

```
use Jkque\StringReplace\StringReplace;

$message = StringReplace::content($string)
    ->when($user, function ($string) use($user) {
        return $string->with(new UserStringReplace($user));
    })
    ->variables([
        '&#39;' => "'",
        '&#63;' => '?'
    ])
    ->replace();
```

```
use Jkque\StringReplace\StringReplace;

use App\User;

class UserStringReplace extends StringReplace
{
    public function __construct(User $user)
    {
        $this->variables([
            '@name' => $user->name,
        ]);
    }
}
```

Usage
-----

[](#usage)

```
use Jkque\StringReplace\StringReplace;

$string = 'We are awesome in php replacethis';

$string = StringReplace::content($string)
    ->variables([
        'replacethis' => 'coding',
    ])
    ->replace(); // the ending method to be called
```

You can use conditional closures `when` and `unless`

```
$string->when($somecondtion, function ($string) {
 // do something;
})
```

By default html tags is being strip but you can turn it off by passing a false value in `stripTags(false)` method.

### Pipeline

[](#pipeline)

To breakdown complex process into individual tasks you can create a class that extends `Jkque\StringReplace\StringReplace`

```
use Jkque\StringReplace\StringReplace;

class RemoveBadWords extends StringReplace
{
    public function __construct()
    {
        $this->variables([
            'badword' => '*',
        ]);
    }
}
```

A helper command to create this class `php artisan string-replace:pipe {name} {model? : With model}`. You can change the namespace of your model in the config file the default is 'App\\'.

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

[](#installation)

You can install the package via composer:

```
composer require jkque/laravel-string-replace
```

publish config files

```
php artisan vendor:publish --provider="Jkque\StringReplace\StringReplaceServiceProvider"
```

Testing
-------

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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)

- [John Kevin Cadungog](https://github.com/jkque)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance41

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2144d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e08e73daf5962fe05c21a8ee9a721cf273a6348dcb3996a18fa59261ebabe2d?d=identicon)[jkque](/maintainers/jkque)

---

Top Contributors

[![jkque](https://avatars.githubusercontent.com/u/5366722?v=4)](https://github.com/jkque "jkque (17 commits)")

---

Tags

jkquelaravel-string-replace

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jkque-laravel-string-replace/health.svg)

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

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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