Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adds Str::remove and Str::of('foobar')->remove methods #36639

Merged
merged 5 commits into from
Mar 18, 2021
Merged

[8.x] Adds Str::remove and Str::of('foobar')->remove methods #36639

merged 5 commits into from
Mar 18, 2021

Conversation

lukeraymonddowning
Copy link
Contributor

@lukeraymonddowning lukeraymonddowning commented Mar 17, 2021

It always annoyed me that there was no str_remove method in PHP. I know that you can do str_replace and pass '', but I think it makes the code a fair bit harder to parse visually.

This PR adds remove($value) to the Str and Stringable classes.

Usage

// Fbar
Str::remove('o', 'Foobar');
Str::of('Foobar')->remove('o');

// Fbr
Str::remove(['o', 'a'], 'Foobar');
Str::of('Foobar')->remove(['o', 'a']);

I think it makes it much easier when dealing with complex string manipulation to quickly get a sense of what's happening.

This PR also adds an extra layer of functionality by allowing the removal of items in a case insensitive manner by passing false as the last parameter:

// oobar
Str::remove('f', 'Foobar', false);
Str::of('Foobar')->remove('f', false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants