From 2ea70668c986b6f2c683cca8802ea2d49ad604c2 Mon Sep 17 00:00:00 2001
From: Balboa <20909423+balboacodes@users.noreply.github.com>
Date: Sat, 5 Jul 2025 10:27:15 -0400
Subject: [PATCH] wip
---
strings.md | 545 ++++++++++++++++++++++++++---------------------------
1 file changed, 272 insertions(+), 273 deletions(-)
diff --git a/strings.md b/strings.md
index 2302d2bb84..6aaf1aa394 100644
--- a/strings.md
+++ b/strings.md
@@ -43,14 +43,14 @@ 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::chopStart](#method-str-chop-start)
[Str::contains](#method-str-contains)
[Str::containsAll](#method-str-contains-all)
+[Str::deduplicate](#method-deduplicate)
[Str::doesntContain](#method-str-doesnt-contain)
[Str::doesntEndWith](#method-str-doesnt-end-with)
[Str::doesntStartWith](#method-str-doesnt-start-with)
-[Str::deduplicate](#method-deduplicate)
[Str::endsWith](#method-ends-with)
[Str::excerpt](#method-excerpt)
[Str::finish](#method-str-finish)
@@ -68,6 +68,7 @@ Laravel includes a variety of functions for manipulating string values. Many of
[Str::length](#method-str-length)
[Str::limit](#method-str-limit)
[Str::lower](#method-str-lower)
+[Str::ltrim](#method-str-ltrim)
[Str::markdown](#method-str-markdown)
[Str::mask](#method-str-mask)
[Str::match](#method-str-match)
@@ -85,12 +86,13 @@ Laravel includes a variety of functions for manipulating string values. Many of
[Str::repeat](#method-str-repeat)
[Str::replace](#method-str-replace)
[Str::replaceArray](#method-str-replace-array)
+[Str::replaceEnd](#method-str-replace-end)
[Str::replaceFirst](#method-str-replace-first)
[Str::replaceLast](#method-str-replace-last)
[Str::replaceMatches](#method-str-replace-matches)
[Str::replaceStart](#method-str-replace-start)
-[Str::replaceEnd](#method-str-replace-end)
[Str::reverse](#method-str-reverse)
+[Str::rtrim](#method-str-rtrim)
[Str::singular](#method-str-singular)
[Str::slug](#method-str-slug)
[Str::snake](#method-snake-case)
@@ -107,18 +109,16 @@ Laravel includes a variety of functions for manipulating string values. Many of
[Str::toBase64](#method-str-to-base64)
[Str::transliterate](#method-str-transliterate)
[Str::trim](#method-str-trim)
-[Str::ltrim](#method-str-ltrim)
-[Str::rtrim](#method-str-rtrim)
[Str::ucfirst](#method-str-ucfirst)
[Str::ucsplit](#method-str-ucsplit)
-[Str::upper](#method-str-upper)
[Str::ulid](#method-str-ulid)
[Str::unwrap](#method-str-unwrap)
+[Str::upper](#method-str-upper)
[Str::uuid](#method-str-uuid)
[Str::uuid7](#method-str-uuid7)
[Str::wordCount](#method-str-word-count)
-[Str::wordWrap](#method-str-word-wrap)
[Str::words](#method-str-words)
+[Str::wordWrap](#method-str-word-wrap)
[Str::wrap](#method-str-wrap)
[str](#method-str)
[trans](#method-trans)
@@ -143,9 +143,9 @@ Laravel includes a variety of functions for manipulating string values. Many of
[betweenFirst](#method-fluent-str-between-first)
[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)
+[chopStart](#method-fluent-str-chop-start)
+[classBasename](#method-fluent-str-class-basename)
[contains](#method-fluent-str-contains)
[containsAll](#method-fluent-str-contains-all)
[decrypt](#method-fluent-str-decrypt)
@@ -166,8 +166,9 @@ Laravel includes a variety of functions for manipulating string values. Many of
[is](#method-fluent-str-is)
[isAscii](#method-fluent-str-is-ascii)
[isEmpty](#method-fluent-str-is-empty)
-[isNotEmpty](#method-fluent-str-is-not-empty)
[isJson](#method-fluent-str-is-json)
+[isMatch](#method-fluent-str-is-match)
+[isNotEmpty](#method-fluent-str-is-not-empty)
[isUlid](#method-fluent-str-is-ulid)
[isUrl](#method-fluent-str-is-url)
[isUuid](#method-fluent-str-is-uuid)
@@ -176,11 +177,11 @@ Laravel includes a variety of functions for manipulating string values. Many of
[length](#method-fluent-str-length)
[limit](#method-fluent-str-limit)
[lower](#method-fluent-str-lower)
+[ltrim](#method-fluent-str-ltrim)
[markdown](#method-fluent-str-markdown)
[mask](#method-fluent-str-mask)
[match](#method-fluent-str-match)
[matchAll](#method-fluent-str-match-all)
-[isMatch](#method-fluent-str-is-match)
[newLine](#method-fluent-str-new-line)
[padBoth](#method-fluent-str-padboth)
[padLeft](#method-fluent-str-padleft)
@@ -193,11 +194,12 @@ Laravel includes a variety of functions for manipulating string values. Many of
[repeat](#method-fluent-str-repeat)
[replace](#method-fluent-str-replace)
[replaceArray](#method-fluent-str-replace-array)
+[replaceEnd](#method-fluent-str-replace-end)
[replaceFirst](#method-fluent-str-replace-first)
[replaceLast](#method-fluent-str-replace-last)
[replaceMatches](#method-fluent-str-replace-matches)
[replaceStart](#method-fluent-str-replace-start)
-[replaceEnd](#method-fluent-str-replace-end)
+[rtrim](#method-fluent-str-rtrim)
[scan](#method-fluent-str-scan)
[singular](#method-fluent-str-singular)
[slug](#method-fluent-str-slug)
@@ -220,8 +222,6 @@ Laravel includes a variety of functions for manipulating string values. Many of
[toUri](#method-fluent-str-to-uri)
[transliterate](#method-fluent-str-transliterate)
[trim](#method-fluent-str-trim)
-[ltrim](#method-fluent-str-ltrim)
-[rtrim](#method-fluent-str-rtrim)
[ucfirst](#method-fluent-str-ucfirst)
[ucsplit](#method-fluent-str-ucsplit)
[unwrap](#method-fluent-str-unwrap)
@@ -232,15 +232,15 @@ Laravel includes a variety of functions for manipulating string values. Many of
[whenDoesntEndWith](#method-fluent-str-when-doesnt-end-with)
[whenDoesntStartWith](#method-fluent-str-when-doesnt-start-with)
[whenEmpty](#method-fluent-str-when-empty)
-[whenNotEmpty](#method-fluent-str-when-not-empty)
-[whenStartsWith](#method-fluent-str-when-starts-with)
[whenEndsWith](#method-fluent-str-when-ends-with)
[whenExactly](#method-fluent-str-when-exactly)
-[whenNotExactly](#method-fluent-str-when-not-exactly)
[whenIs](#method-fluent-str-when-is)
[whenIsAscii](#method-fluent-str-when-is-ascii)
[whenIsUlid](#method-fluent-str-when-is-ulid)
[whenIsUuid](#method-fluent-str-when-is-uuid)
+[whenNotEmpty](#method-fluent-str-when-not-empty)
+[whenNotExactly](#method-fluent-str-when-not-exactly)
+[whenStartsWith](#method-fluent-str-when-starts-with)
[whenTest](#method-fluent-str-when-test)
[wordCount](#method-fluent-str-word-count)
[words](#method-fluent-str-words)
@@ -429,48 +429,48 @@ $character = Str::charAt('This is my name.', 6);
// 's'
```
-
-#### `Str::chopStart()` {.collection-method}
+
+#### `Str::chopEnd()` {.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:
+The `Str::chopEnd` method removes the last occurrence of the given value only if the value appears at the end of the string:
```php
use Illuminate\Support\Str;
-$url = Str::chopStart('https://laravel.com', 'https://');
+$url = Str::chopEnd('app/Models/Photograph.php', '.php');
-// 'laravel.com'
+// 'app/Models/Photograph'
```
-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:
+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:
```php
use Illuminate\Support\Str;
-$url = Str::chopStart('http://laravel.com', ['https://', 'http://']);
+$url = Str::chopEnd('laravel.com/index.php', ['/index.html', '/index.php']);
// 'laravel.com'
```
-
-#### `Str::chopEnd()` {.collection-method}
+
+#### `Str::chopStart()` {.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:
+The `Str::chopStart` method removes the first occurrence of the given value only if the value appears at the start of the string:
```php
use Illuminate\Support\Str;
-$url = Str::chopEnd('app/Models/Photograph.php', '.php');
+$url = Str::chopStart('https://laravel.com', 'https://');
-// 'app/Models/Photograph'
+// 'laravel.com'
```
-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:
+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:
```php
use Illuminate\Support\Str;
-$url = Str::chopEnd('laravel.com/index.php', ['/index.html', '/index.php']);
+$url = Str::chopStart('http://laravel.com', ['https://', 'http://']);
// 'laravel.com'
```
@@ -531,60 +531,60 @@ $containsAll = Str::containsAll('This is my name', ['MY', 'NAME'], ignoreCase: t
// true
```
-
-#### `Str::doesntContain()` {.collection-method}
+
+#### `Str::deduplicate()` {.collection-method}
-The `Str::doesntContain` method determines if the given string doesn't contain the given value. By default, this method is case sensitive:
+The `Str::deduplicate` method replaces consecutive instances of a character with a single instance of that character in the given string. By default, the method deduplicates spaces:
```php
use Illuminate\Support\Str;
-$doesntContain = Str::doesntContain('This is name', 'my');
+$result = Str::deduplicate('The Laravel Framework');
-// true
+// The Laravel Framework
```
-You may also pass an array of values to determine if the given string doesn't contain any of the values in the array:
+You may specify a different character to deduplicate by passing it in as the second argument to the method:
```php
use Illuminate\Support\Str;
-$doesntContain = Str::doesntContain('This is name', ['my', 'foo']);
+$result = Str::deduplicate('The---Laravel---Framework', '-');
-// true
+// The-Laravel-Framework
```
-You may disable case sensitivity by setting the `ignoreCase` argument to `true`:
+
+#### `Str::doesntContain()` {.collection-method}
+
+The `Str::doesntContain` method determines if the given string doesn't contain the given value. By default, this method is case sensitive:
```php
use Illuminate\Support\Str;
-$doesntContain = Str::doesntContain('This is name', 'MY', ignoreCase: true);
+$doesntContain = Str::doesntContain('This is name', 'my');
// true
```
-
-#### `Str::deduplicate()` {.collection-method}
-
-The `Str::deduplicate` method replaces consecutive instances of a character with a single instance of that character in the given string. By default, the method deduplicates spaces:
+You may also pass an array of values to determine if the given string doesn't contain any of the values in the array:
```php
use Illuminate\Support\Str;
-$result = Str::deduplicate('The Laravel Framework');
+$doesntContain = Str::doesntContain('This is name', ['my', 'foo']);
-// The Laravel Framework
+// true
```
-You may specify a different character to deduplicate by passing it in as the second argument to the method:
+You may disable case sensitivity by setting the `ignoreCase` argument to `true`:
```php
use Illuminate\Support\Str;
-$result = Str::deduplicate('The---Laravel---Framework', '-');
+$doesntContain = Str::doesntContain('This is name', 'MY', ignoreCase: true);
-// The-Laravel-Framework
+// true
```
@@ -832,46 +832,46 @@ $result = Str::isJson('{first: "John", last: "Doe"}');
// false
```
-
-#### `Str::isUrl()` {.collection-method}
+
+#### `Str::isUlid()` {.collection-method}
-The `Str::isUrl` method determines if the given string is a valid URL:
+The `Str::isUlid` method determines if the given string is a valid ULID:
```php
use Illuminate\Support\Str;
-$isUrl = Str::isUrl('http://example.com');
+$isUlid = Str::isUlid('01gd6r360bp37zj17nxb55yv40');
// true
-$isUrl = Str::isUrl('laravel');
+$isUlid = Str::isUlid('laravel');
// false
```
-The `isUrl` method considers a wide range of protocols as valid. However, you may specify the protocols that should be considered valid by providing them to the `isUrl` method:
-
-```php
-$isUrl = Str::isUrl('http://example.com', ['http', 'https']);
-```
-
-
-#### `Str::isUlid()` {.collection-method}
+
+#### `Str::isUrl()` {.collection-method}
-The `Str::isUlid` method determines if the given string is a valid ULID:
+The `Str::isUrl` method determines if the given string is a valid URL:
```php
use Illuminate\Support\Str;
-$isUlid = Str::isUlid('01gd6r360bp37zj17nxb55yv40');
+$isUrl = Str::isUrl('http://example.com');
// true
-$isUlid = Str::isUlid('laravel');
+$isUrl = Str::isUrl('laravel');
// false
```
+The `isUrl` method considers a wide range of protocols as valid. However, you may specify the protocols that should be considered valid by providing them to the `isUrl` method:
+
+```php
+$isUrl = Str::isUrl('http://example.com', ['http', 'https']);
+```
+
#### `Str::isUuid()` {.collection-method}
@@ -970,6 +970,19 @@ $converted = Str::lower('LARAVEL');
// laravel
```
+
+#### `Str::ltrim()` {.collection-method}
+
+The `Str::ltrim` method strips whitespace (or other characters) from the beginning of the given string. Unlike PHP's native `ltrim` function, the `Str::ltrim` method also removes unicode whitespace characters:
+
+```php
+use Illuminate\Support\Str;
+
+$string = Str::ltrim(' foo bar ');
+
+// 'foo bar '
+```
+
#### `Str::markdown()` {.collection-method}
@@ -1325,6 +1338,23 @@ $replaced = Str::replaceArray('?', ['8:30', '9:00'], $string);
// The event will take place between 8:30 and 9:00
```
+
+#### `Str::replaceEnd()` {.collection-method}
+
+The `Str::replaceEnd` method replaces the last occurrence of the given value only if the value appears at the end of the string:
+
+```php
+use Illuminate\Support\Str;
+
+$replaced = Str::replaceEnd('World', 'Laravel', 'Hello World');
+
+// Hello Laravel
+
+$replaced = Str::replaceEnd('Hello', 'Laravel', 'Hello World');
+
+// Hello World
+```
+
#### `Str::replaceFirst()` {.collection-method}
@@ -1397,34 +1427,30 @@ $replaced = Str::replaceStart('World', 'Laravel', 'Hello World');
// Hello World
```
-
-#### `Str::replaceEnd()` {.collection-method}
+
+#### `Str::reverse()` {.collection-method}
-The `Str::replaceEnd` method replaces the last occurrence of the given value only if the value appears at the end of the string:
+The `Str::reverse` method reverses the given string:
```php
use Illuminate\Support\Str;
-$replaced = Str::replaceEnd('World', 'Laravel', 'Hello World');
-
-// Hello Laravel
-
-$replaced = Str::replaceEnd('Hello', 'Laravel', 'Hello World');
+$reversed = Str::reverse('Hello World');
-// Hello World
+// dlroW olleH
```
-
-#### `Str::reverse()` {.collection-method}
+
+#### `Str::rtrim()` {.collection-method}
-The `Str::reverse` method reverses the given string:
+The `Str::rtrim` method strips whitespace (or other characters) from the end of the given string. Unlike PHP's native `rtrim` function, the `Str::rtrim` method also removes unicode whitespace characters:
```php
use Illuminate\Support\Str;
-$reversed = Str::reverse('Hello World');
+$string = Str::rtrim(' foo bar ');
-// dlroW olleH
+// ' foo bar'
```
@@ -1660,32 +1686,6 @@ $string = Str::trim(' foo bar ');
// 'foo bar'
```
-
-#### `Str::ltrim()` {.collection-method}
-
-The `Str::ltrim` method strips whitespace (or other characters) from the beginning of the given string. Unlike PHP's native `ltrim` function, the `Str::ltrim` method also removes unicode whitespace characters:
-
-```php
-use Illuminate\Support\Str;
-
-$string = Str::ltrim(' foo bar ');
-
-// 'foo bar '
-```
-
-
-#### `Str::rtrim()` {.collection-method}
-
-The `Str::rtrim` method strips whitespace (or other characters) from the end of the given string. Unlike PHP's native `rtrim` function, the `Str::rtrim` method also removes unicode whitespace characters:
-
-```php
-use Illuminate\Support\Str;
-
-$string = Str::rtrim(' foo bar ');
-
-// ' foo bar'
-```
-
#### `Str::ucfirst()` {.collection-method}
@@ -1712,19 +1712,6 @@ $segments = Str::ucsplit('FooBar');
// [0 => 'Foo', 1 => 'Bar']
```
-
-#### `Str::upper()` {.collection-method}
-
-The `Str::upper` method converts the given string to uppercase:
-
-```php
-use Illuminate\Support\Str;
-
-$string = Str::upper('laravel');
-
-// LARAVEL
-```
-
#### `Str::ulid()` {.collection-method}
@@ -1780,6 +1767,19 @@ Str::unwrap('{framework: "Laravel"}', '{', '}');
// framework: "Laravel"
```
+
+#### `Str::upper()` {.collection-method}
+
+The `Str::upper` method converts the given string to uppercase:
+
+```php
+use Illuminate\Support\Str;
+
+$string = Str::upper('laravel');
+
+// LARAVEL
+```
+
#### `Str::uuid()` {.collection-method}
@@ -1835,6 +1835,19 @@ use Illuminate\Support\Str;
Str::wordCount('Hello, world!'); // 2
```
+
+#### `Str::words()` {.collection-method}
+
+The `Str::words` method limits the number of words in a string. An additional string may be passed to this method via its third argument to specify which string should be appended to the end of the truncated string:
+
+```php
+use Illuminate\Support\Str;
+
+return Str::words('Perfectly balanced, as all things should be.', 3, ' >>>');
+
+// Perfectly balanced, as >>>
+```
+
#### `Str::wordWrap()` {.collection-method}
@@ -1854,21 +1867,8 @@ dog.
*/
```
-
-#### `Str::words()` {.collection-method}
-
-The `Str::words` method limits the number of words in a string. An additional string may be passed to this method via its third argument to specify which string should be appended to the end of the truncated string:
-
-```php
-use Illuminate\Support\Str;
-
-return Str::words('Perfectly balanced, as all things should be.', 3, ' >>>');
-
-// Perfectly balanced, as >>>
-```
-
-
-#### `Str::wrap()` {.collection-method}
+
+#### `Str::wrap()` {.collection-method}
The `Str::wrap` method wraps the given string with an additional string or pair of strings:
@@ -2096,17 +2096,27 @@ $character = Str::of('This is my name.')->charAt(6);
// 's'
```
-
-#### `classBasename` {.collection-method}
+
+#### `chopEnd` {.collection-method}
-The `classBasename` method returns the class name of the given class with the class's namespace removed:
+The `chopEnd` method removes the last occurrence of the given value only if the value appears at the end of the string:
```php
use Illuminate\Support\Str;
-$class = Str::of('Foo\Bar\Baz')->classBasename();
+$url = Str::of('https://laravel.com')->chopEnd('.com');
-// 'Baz'
+// 'https://laravel'
+```
+
+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:
+
+```php
+use Illuminate\Support\Str;
+
+$url = Str::of('http://laravel.com')->chopEnd(['.com', '.io']);
+
+// 'http://laravel'
```
@@ -2132,27 +2142,17 @@ $url = Str::of('http://laravel.com')->chopStart(['https://', 'http://']);
// 'laravel.com'
```
-
-#### `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:
-
-```php
-use Illuminate\Support\Str;
-
-$url = Str::of('https://laravel.com')->chopEnd('.com');
-
-// 'https://laravel'
-```
+
+#### `classBasename` {.collection-method}
-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:
+The `classBasename` method returns the class name of the given class with the class's namespace removed:
```php
use Illuminate\Support\Str;
-$url = Str::of('http://laravel.com')->chopEnd(['.com', '.io']);
+$class = Str::of('Foo\Bar\Baz')->classBasename();
-// 'http://laravel'
+// 'Baz'
```
@@ -2557,42 +2557,59 @@ $result = Str::of('Laravel')->trim()->isEmpty();
// false
```
-
-#### `isNotEmpty` {.collection-method}
+
+#### `isJson` {.collection-method}
-The `isNotEmpty` method determines if the given string is not empty:
+The `isJson` method determines if a given string is valid JSON:
```php
use Illuminate\Support\Str;
-$result = Str::of(' ')->trim()->isNotEmpty();
+$result = Str::of('[1,2,3]')->isJson();
-// false
+// true
-$result = Str::of('Laravel')->trim()->isNotEmpty();
+$result = Str::of('{"first": "John", "last": "Doe"}')->isJson();
// true
+
+$result = Str::of('{first: "John", last: "Doe"}')->isJson();
+
+// false
```
-
-#### `isJson` {.collection-method}
+
+#### `isMatch` {.collection-method}
-The `isJson` method determines if a given string is valid JSON:
+The `isMatch` method will return `true` if the string matches a given regular expression:
```php
use Illuminate\Support\Str;
-$result = Str::of('[1,2,3]')->isJson();
+$result = Str::of('foo bar')->isMatch('/foo (.*)/');
// true
-$result = Str::of('{"first": "John", "last": "Doe"}')->isJson();
+$result = Str::of('laravel')->isMatch('/foo (.*)/');
-// true
+// false
+```
-$result = Str::of('{first: "John", last: "Doe"}')->isJson();
+
+#### `isNotEmpty` {.collection-method}
+
+The `isNotEmpty` method determines if the given string is not empty:
+
+```php
+use Illuminate\Support\Str;
+
+$result = Str::of(' ')->trim()->isNotEmpty();
// false
+
+$result = Str::of('Laravel')->trim()->isNotEmpty();
+
+// true
```
@@ -2733,6 +2750,23 @@ $result = Str::of('LARAVEL')->lower();
// 'laravel'
```
+
+#### `ltrim` {.collection-method}
+
+The `ltrim` method trims the left side of the string. Unlike PHP's native `ltrim` function, Laravel's `ltrim` method also removes unicode whitespace characters:
+
+```php
+use Illuminate\Support\Str;
+
+$string = Str::of(' Laravel ')->ltrim();
+
+// 'Laravel '
+
+$string = Str::of('/Laravel/')->ltrim('/');
+
+// 'Laravel/'
+```
+
#### `markdown` {.collection-method}
@@ -2834,23 +2868,6 @@ $result = Str::of('bar fun bar fly')->matchAll('/f(\w*)/');
If no matches are found, an empty collection will be returned.
-
-#### `isMatch` {.collection-method}
-
-The `isMatch` method will return `true` if the string matches a given regular expression:
-
-```php
-use Illuminate\Support\Str;
-
-$result = Str::of('foo bar')->isMatch('/foo (.*)/');
-
-// true
-
-$result = Str::of('laravel')->isMatch('/foo (.*)/');
-
-// false
-```
-
#### `newLine` {.collection-method}
@@ -3060,6 +3077,22 @@ $replaced = Str::of($string)->replaceArray('?', ['8:30', '9:00']);
// The event will take place between 8:30 and 9:00
```
+
+#### `replaceEnd` {.collection-method}
+
+The `replaceEnd` method replaces the last occurrence of the given value only if the value appears at the end of the string:
+
+```php
+use Illuminate\Support\Str;
+
+$replaced = Str::of('Hello World')->replaceEnd('World', 'Laravel');
+
+// Hello Laravel
+
+$replaced = Str::of('Hello World')->replaceEnd('Hello', 'Laravel');
+
+// Hello World
+```
#### `replaceFirst` {.collection-method}
@@ -3129,21 +3162,21 @@ $replaced = Str::of('Hello World')->replaceStart('World', 'Laravel');
// Hello World
```
-
-#### `replaceEnd` {.collection-method}
+
+#### `rtrim` {.collection-method}
-The `replaceEnd` method replaces the last occurrence of the given value only if the value appears at the end of the string:
+The `rtrim` method trims the right side of the given string. Unlike PHP's native `rtrim` function, Laravel's `rtrim` method also removes unicode whitespace characters:
```php
use Illuminate\Support\Str;
-$replaced = Str::of('Hello World')->replaceEnd('World', 'Laravel');
+$string = Str::of(' Laravel ')->rtrim();
-// Hello Laravel
+// ' Laravel'
-$replaced = Str::of('Hello World')->replaceEnd('Hello', 'Laravel');
+$string = Str::of('/Laravel/')->rtrim('/');
-// Hello World
+// '/Laravel'
```
@@ -3462,40 +3495,6 @@ $string = Str::of('/Laravel/')->trim('/');
// 'Laravel'
```
-
-#### `ltrim` {.collection-method}
-
-The `ltrim` method trims the left side of the string. Unlike PHP's native `ltrim` function, Laravel's `ltrim` method also removes unicode whitespace characters:
-
-```php
-use Illuminate\Support\Str;
-
-$string = Str::of(' Laravel ')->ltrim();
-
-// 'Laravel '
-
-$string = Str::of('/Laravel/')->ltrim('/');
-
-// 'Laravel/'
-```
-
-
-#### `rtrim` {.collection-method}
-
-The `rtrim` method trims the right side of the given string. Unlike PHP's native `rtrim` function, Laravel's `rtrim` method also removes unicode whitespace characters:
-
-```php
-use Illuminate\Support\Str;
-
-$string = Str::of(' Laravel ')->rtrim();
-
-// ' Laravel'
-
-$string = Str::of('/Laravel/')->rtrim('/');
-
-// '/Laravel'
-```
-
#### `ucfirst` {.collection-method}
@@ -3671,38 +3670,6 @@ $string = Str::of(' ')->trim()->whenEmpty(function (Stringable $string) {
// 'Laravel'
```
-
-#### `whenNotEmpty` {.collection-method}
-
-The `whenNotEmpty` method invokes the given closure if the string is not empty. If the closure returns a value, that value will also be returned by the `whenNotEmpty` method. If the closure does not return a value, the fluent string instance will be returned:
-
-```php
-use Illuminate\Support\Str;
-use Illuminate\Support\Stringable;
-
-$string = Str::of('Framework')->whenNotEmpty(function (Stringable $string) {
- return $string->prepend('Laravel ');
-});
-
-// 'Laravel Framework'
-```
-
-
-#### `whenStartsWith` {.collection-method}
-
-The `whenStartsWith` method invokes the given closure if the string starts with the given sub-string. The closure will receive the fluent string instance:
-
-```php
-use Illuminate\Support\Str;
-use Illuminate\Support\Stringable;
-
-$string = Str::of('disney world')->whenStartsWith('disney', function (Stringable $string) {
- return $string->title();
-});
-
-// 'Disney World'
-```
-
#### `whenEndsWith` {.collection-method}
@@ -3735,22 +3702,6 @@ $string = Str::of('laravel')->whenExactly('laravel', function (Stringable $strin
// 'Laravel'
```
-
-#### `whenNotExactly` {.collection-method}
-
-The `whenNotExactly` method invokes the given closure if the string does not exactly match the given string. The closure will receive the fluent string instance:
-
-```php
-use Illuminate\Support\Str;
-use Illuminate\Support\Stringable;
-
-$string = Str::of('framework')->whenNotExactly('laravel', function (Stringable $string) {
- return $string->title();
-});
-
-// 'Framework'
-```
-
#### `whenIs` {.collection-method}
@@ -3814,6 +3765,54 @@ $string = Str::of('a0a2a2d2-0b87-4a18-83f2-2529882be2de')->whenIsUuid(function (
// 'a0a2a2d2'
```
+
+#### `whenNotEmpty` {.collection-method}
+
+The `whenNotEmpty` method invokes the given closure if the string is not empty. If the closure returns a value, that value will also be returned by the `whenNotEmpty` method. If the closure does not return a value, the fluent string instance will be returned:
+
+```php
+use Illuminate\Support\Str;
+use Illuminate\Support\Stringable;
+
+$string = Str::of('Framework')->whenNotEmpty(function (Stringable $string) {
+ return $string->prepend('Laravel ');
+});
+
+// 'Laravel Framework'
+```
+
+
+#### `whenNotExactly` {.collection-method}
+
+The `whenNotExactly` method invokes the given closure if the string does not exactly match the given string. The closure will receive the fluent string instance:
+
+```php
+use Illuminate\Support\Str;
+use Illuminate\Support\Stringable;
+
+$string = Str::of('framework')->whenNotExactly('laravel', function (Stringable $string) {
+ return $string->title();
+});
+
+// 'Framework'
+```
+
+
+#### `whenStartsWith` {.collection-method}
+
+The `whenStartsWith` method invokes the given closure if the string starts with the given sub-string. The closure will receive the fluent string instance:
+
+```php
+use Illuminate\Support\Str;
+use Illuminate\Support\Stringable;
+
+$string = Str::of('disney world')->whenStartsWith('disney', function (Stringable $string) {
+ return $string->title();
+});
+
+// 'Disney World'
+```
+
#### `whenTest` {.collection-method}