From 30f99aa30c38267ca1e4f47911b571d3abb07a77 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 14 Feb 2022 18:07:48 +0000 Subject: [PATCH 1/2] Adds `Str::excerpt` documentation --- helpers.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/helpers.md b/helpers.md index 4bfc5809e89..015b45af13e 100644 --- a/helpers.md +++ b/helpers.md @@ -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) @@ -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) @@ -1274,6 +1276,32 @@ You may also pass an array of values to determine if the given string ends with // false + +#### `Str::excerpt()` {.collection-method} + +The `Str::excerpt` method extracts an excerpt from text that matches the first instance of a phrase: + + use Illuminate\Support\Str; + + $excerpt = Str::excerpt('This is my name', 'my', [ + 'radius' => 3 + ]); + + // '...is my na...' + +The `radius` option defaults to `100`, and it allows to define the number of characters that should appear on each side of the truncated string. + +Also, 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::excerpt('This is my name', 'name', [ + 'radius' => 3, + 'omission' => '(...) ' + ]); + + // '(...) my name' + #### `Str::finish()` {.collection-method} @@ -2027,6 +2055,32 @@ If necessary, you may specify how many directory levels you wish to trim from th // '/foo' + +#### `excerpt` {.collection-method} + +The `excerpt` method extracts an excerpt from text that matches the first instance of a phrase: + + use Illuminate\Support\Str; + + $excerpt = Str::of('This is my name')->excerpt('my', [ + 'radius' => 3 + ]); + + // '...is my na...' + +The `radius` option defaults to `100`, and it allows to define the number of characters that should appear on each side of the truncated string. + +Also, 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' + #### `endsWith` {.collection-method} From 7be7b14d0789da9220637495f7cdde8f340dc0fd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 14 Feb 2022 15:56:53 -0600 Subject: [PATCH 2/2] formatting --- helpers.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/helpers.md b/helpers.md index 015b45af13e..d26757a8f99 100644 --- a/helpers.md +++ b/helpers.md @@ -1279,7 +1279,7 @@ You may also pass an array of values to determine if the given string ends with #### `Str::excerpt()` {.collection-method} -The `Str::excerpt` method extracts an excerpt from text that matches the first instance of a phrase: +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; @@ -1289,9 +1289,9 @@ The `Str::excerpt` method extracts an excerpt from text that matches the first i // '...is my na...' -The `radius` option defaults to `100`, and it allows to define the number of characters that should appear on each side of the truncated string. +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. -Also, you may use the `omission` option to change the string that will be prepended and appended to 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; @@ -2058,7 +2058,7 @@ If necessary, you may specify how many directory levels you wish to trim from th #### `excerpt` {.collection-method} -The `excerpt` method extracts an excerpt from text that matches the first instance of a phrase: +The `excerpt` method extracts an excerpt from the string that matches the first instance of a phrase within that string: use Illuminate\Support\Str; @@ -2068,9 +2068,9 @@ The `excerpt` method extracts an excerpt from text that matches the first instan // '...is my na...' -The `radius` option defaults to `100`, and it allows to define the number of characters that should appear on each side of the truncated string. +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. -Also, you may use the `omission` option to change the string that will be prepended and appended to 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;