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

[9.x] Adds Str::excerpt documentation #7715

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
[Str::contains](#method-str-contains)
[Str::containsAll](#method-str-contains-all)
[Str::endsWith](#method-ends-with)
[Str::excerpt](#method-excerpt)
[Str::finish](#method-str-finish)
[Str::headline](#method-str-headline)
[Str::is](#method-str-is)
Expand Down Expand Up @@ -166,6 +167,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
[containsAll](#method-fluent-str-contains-all)
[dirname](#method-fluent-str-dirname)
[endsWith](#method-fluent-str-ends-with)
[excerpt](#method-fluent-str-excerpt)
[exactly](#method-fluent-str-exactly)
[explode](#method-fluent-str-explode)
[finish](#method-fluent-str-finish)
Expand Down Expand Up @@ -1274,6 +1276,32 @@ You may also pass an array of values to determine if the given string ends with

// false

<a name="method-excerpt"></a>
#### `Str::excerpt()` {.collection-method}

The `Str::excerpt` method extracts an excerpt from a given string that matches the first instance of a phrase within that string:

use Illuminate\Support\Str;

$excerpt = Str::excerpt('This is my name', 'my', [
'radius' => 3
]);

// '...is my na...'

The `radius` option, which defaults to `100`, allows you to define the number of characters that should appear on each side of the truncated string.

In addition, you may use the `omission` option to define the string that will be prepended and appended to the truncated string:

use Illuminate\Support\Str;

$excerpt = Str::excerpt('This is my name', 'name', [
'radius' => 3,
'omission' => '(...) '
]);

// '(...) my name'

<a name="method-str-finish"></a>
#### `Str::finish()` {.collection-method}

Expand Down Expand Up @@ -2027,6 +2055,32 @@ If necessary, you may specify how many directory levels you wish to trim from th

// '/foo'

<a name="method-fluent-str-excerpt"></a>
#### `excerpt` {.collection-method}

The `excerpt` method extracts an excerpt from the string that matches the first instance of a phrase within that string:

use Illuminate\Support\Str;

$excerpt = Str::of('This is my name')->excerpt('my', [
'radius' => 3
]);

// '...is my na...'

The `radius` option, which defaults to `100`, allows you to define the number of characters that should appear on each side of the truncated string.

In addition, you may use the `omission` option to change the string that will be prepended and appended to the truncated string:

use Illuminate\Support\Str;

$excerpt = Str::of('This is my name')->excerpt('name', [
'radius' => 3,
'omission' => '(...) '
]);

// '(...) my name'

<a name="method-fluent-str-ends-with"></a>
#### `endsWith` {.collection-method}

Expand Down