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

[11.x] Document Str::chop* methods #9726

Merged
merged 2 commits into from
Jul 2, 2024
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
80 changes: 80 additions & 0 deletions strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Laravel includes a variety of functions for manipulating string values. Many of
[Str::betweenFirst](#method-str-between-first)
[Str::camel](#method-camel-case)
[Str::charAt](#method-char-at)
[Str::chopStart](#method-str-chop-start)
[Str::chopEnd](#method-str-chop-end)
[Str::contains](#method-str-contains)
[Str::containsAll](#method-str-contains-all)
[Str::endsWith](#method-ends-with)
Expand Down Expand Up @@ -134,6 +136,8 @@ Laravel includes a variety of functions for manipulating string values. Many of
[camel](#method-fluent-str-camel)
[charAt](#method-fluent-str-char-at)
[classBasename](#method-fluent-str-class-basename)
[chopStart](#method-fluent-str-chop-start)
[chopEnd](#method-fluent-str-chop-end)
[contains](#method-fluent-str-contains)
[containsAll](#method-fluent-str-contains-all)
[dirname](#method-fluent-str-dirname)
Expand Down Expand Up @@ -377,6 +381,44 @@ The `Str::charAt` method returns the character at the specified index. If the in

// 's'

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

The `Str::chopStart` method removes the first occurrence of the given value only if the value appears at the start of the string:

use Illuminate\Support\Str;

$url = Str::chopStart('https://laravel.com', 'https://');

// 'laravel.com'

You may also pass an array as the second argument. If the string starts with any of the values in the array then that value will be removed from string:

use Illuminate\Support\Str;

$url = Str::chopStart('http://laravel.com', ['https://', 'http://']);

// 'laravel.com'

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

The `Str::chopEnd` method removes the last occurrence of the given value only if the value appears at the end of the string:

use Illuminate\Support\Str;

$url = Str::chopEnd('app/Models/Photograph.php', '.php');

// 'app/Models/Photograph'

You may also pass an array as the second argument. If the string ends with any of the values in the array then that value will be removed from string:

use Illuminate\Support\Str;

$url = Str::chopEnd('laravel.com/index.php', ['/index.html', '/index.php']);

// 'laravel.com'

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

Expand Down Expand Up @@ -1587,6 +1629,44 @@ The `classBasename` method returns the class name of the given class with the cl

// 'Baz'

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

The `chopStart` method removes the first occurrence of the given value only if the value appears at the start of the string:

use Illuminate\Support\Str;

$url = Str::of('https://laravel.com')->chopStart('https://');

// 'laravel.com'

You may also pass an array. If the string starts with any of the values in the array then that value will be removed from string:

use Illuminate\Support\Str;

$url = Str::of('http://laravel.com')->chopStart(['https://', 'http://']);

// 'laravel.com'

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

The `chopEnd` method removes the last occurrence of the given value only if the value appears at the end of the string:

use Illuminate\Support\Str;

$url = Str::of('https://laravel.com')->chopEnd('https://');

// 'laravel.com'

You may also pass an array. If the string ends with any of the values in the array then that value will be removed from string:

use Illuminate\Support\Str;

$url = Str::of('http://laravel.com')->chopEnd(['https://', 'http://']);

// 'laravel.com'

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

Expand Down