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
Str::excerpt
method to Laravel 9.The original idea comes from Rails
ActionView::Helpers::TextHelper::excerpt
, and extracts an excerpt from the given$text
that matches the first instance of$phrase
.In other words, it just creates a relevant excerpt that contains the given
$phrase
:The
radius
option expands the excerpt on each side of the first occurrence of$phrase
by the number of characters defined inradius
(which defaults to 100). If the excerpt radius overflows the beginning or end of the$text
, then the$omission
option (which defaults to "...") will be prepended/appended accordingly:Of course, if the excerpt radius does not overflows the beginning or end of the
$text
, the no omission is applied:If the
$phrase
isn't found,null
is returned: