Skip to content

Commit 8a54e92

Browse files
Added info on ignoring case for "contains" and "containsAll" methods (#9811)
* Add info on ignoring the case for "contains" and "containsAll" methods Added information on how to ignore the case when using "contains" and "containsAll" methods. * Use named arguments * Update strings.md * Update strings.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 6e5d9d7 commit 8a54e92

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

strings.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ You may also pass an array as the second argument. If the string ends with any o
424424
<a name="method-str-contains"></a>
425425
#### `Str::contains()` {.collection-method}
426426

427-
The `Str::contains` method determines if the given string contains the given value. This method is case sensitive:
427+
The `Str::contains` method determines if the given string contains the given value. By default this method is case sensitive:
428428

429429
use Illuminate\Support\Str;
430430

@@ -440,6 +440,14 @@ You may also pass an array of values to determine if the given string contains a
440440

441441
// true
442442

443+
You may disable case sensitivity by setting the `ignoreCase` argument to `true`:
444+
445+
use Illuminate\Support\Str;
446+
447+
$contains = Str::contains('This is my name', 'MY', ignoreCase: true);
448+
449+
// true
450+
443451
<a name="method-str-contains-all"></a>
444452
#### `Str::containsAll()` {.collection-method}
445453

@@ -451,6 +459,14 @@ The `Str::containsAll` method determines if the given string contains all of the
451459

452460
// true
453461

462+
You may disable case sensitivity by setting the `ignoreCase` argument to `true`:
463+
464+
use Illuminate\Support\Str;
465+
466+
$containsAll = Str::containsAll('This is my name', ['MY', 'NAME'], ignoreCase: true);
467+
468+
// true
469+
454470
<a name="method-ends-with"></a>
455471
#### `Str::endsWith()` {.collection-method}
456472

@@ -1686,7 +1702,7 @@ You may also pass an array. If the string ends with any of the values in the arr
16861702
<a name="method-fluent-str-contains"></a>
16871703
#### `contains` {.collection-method}
16881704

1689-
The `contains` method determines if the given string contains the given value. This method is case sensitive:
1705+
The `contains` method determines if the given string contains the given value. By default this method is case sensitive:
16901706

16911707
use Illuminate\Support\Str;
16921708

@@ -1702,6 +1718,14 @@ You may also pass an array of values to determine if the given string contains a
17021718

17031719
// true
17041720

1721+
You can disable case sensitivity by setting the `ignoreCase` argument to `true`:
1722+
1723+
use Illuminate\Support\Str;
1724+
1725+
$contains = Str::of('This is my name')->contains('MY', ignoreCase: true);
1726+
1727+
// true
1728+
17051729
<a name="method-fluent-str-contains-all"></a>
17061730
#### `containsAll` {.collection-method}
17071731

@@ -1713,6 +1737,14 @@ The `containsAll` method determines if the given string contains all of the valu
17131737

17141738
// true
17151739

1740+
You can disable case sensitivity by setting the `ignoreCase` argument to `true`:
1741+
1742+
use Illuminate\Support\Str;
1743+
1744+
$containsAll = Str::of('This is my name')->containsAll(['MY', 'NAME'], ignoreCase: true);
1745+
1746+
// true
1747+
17161748
<a name="method-fluent-str-dirname"></a>
17171749
#### `dirname` {.collection-method}
17181750

0 commit comments

Comments
 (0)