[8.x] Add Str::substrReplace()
and Str::of($string)->substrReplace()
methods for the PHP native substr_replace()
function
#39988
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds the ability to use the
substr_replace()
on theStr
andStringable
classes.What & why
Developers can now use directly use
Str::substrReplace(...)
andStr::of($string)->substrReplace(...)
.Substring replace can be used to insert a string at a certain position in another string (set the last parameter, the length, to
0
).It can also be used to replace the remainder of a string after a certain position:
The benefit for webdevelopers is that they now have access to the
substr_replace()
method through the Str facade. The biggest benefit is (in my opinion), is that it's also a perfect candidate to be part of the fluent Stringable methods.I'm also willing to PR a docs update for this, but I don't know if maintainers usually take care of updating the docs or if that is a task for contributors.
This is my first PR to Laravel, so please let me know if I missed anything or if there's anything I can improve. Thanks!