@@ -183,10 +183,32 @@ public static function charAt($subject, $index)
183
183
*
184
184
* @param array|string $needles
185
185
*/
186
- public static function contains (string $ haystack , $ needles ): bool
186
+ public static function contains (string $ haystack , mixed $ needles , bool $ ignoreCase = false ): bool
187
+ {
188
+ if ($ ignoreCase ) {
189
+ return static ::containsIgnoreCase ($ haystack , $ needles );
190
+ }
191
+
192
+ foreach ((array ) $ needles as $ needle ) {
193
+ $ needle = (string ) $ needle ;
194
+ if ($ needle !== '' && str_contains ($ haystack , $ needle )) {
195
+ return true ;
196
+ }
197
+ }
198
+
199
+ return false ;
200
+ }
201
+
202
+ /**
203
+ * Determine if a given string contains a given substring regardless of case sensitivity.
204
+ *
205
+ * @param array|string $needles
206
+ */
207
+ public static function containsIgnoreCase (string $ haystack , $ needles ): bool
187
208
{
188
209
foreach ((array ) $ needles as $ needle ) {
189
- if ($ needle !== '' && str_contains ($ haystack , (string ) $ needle )) {
210
+ $ needle = (string ) $ needle ;
211
+ if ($ needle !== '' && stripos ($ haystack , $ needle ) !== false ) {
190
212
return true ;
191
213
}
192
214
}
@@ -197,14 +219,13 @@ public static function contains(string $haystack, $needles): bool
197
219
/**
198
220
* Determine if a given string contains all array values.
199
221
*
200
- * @param string $haystack
201
222
* @param string[] $needles
202
223
* @return bool
203
224
*/
204
- public static function containsAll ($ haystack , array $ needles )
225
+ public static function containsAll (string $ haystack , array $ needles, bool $ ignoreCase = false )
205
226
{
206
227
foreach ($ needles as $ needle ) {
207
- if (! static ::contains ($ haystack , $ needle )) {
228
+ if (! static ::contains ($ haystack , $ needle, $ ignoreCase )) {
208
229
return false ;
209
230
}
210
231
}
@@ -221,7 +242,8 @@ public static function containsAll($haystack, array $needles)
221
242
public static function endsWith (string $ haystack , $ needles )
222
243
{
223
244
foreach ((array ) $ needles as $ needle ) {
224
- if ($ needle !== '' && str_ends_with ($ haystack , (string ) $ needle )) {
245
+ $ needle = (string ) $ needle ;
246
+ if ($ needle !== '' && str_ends_with ($ haystack , $ needle )) {
225
247
return true ;
226
248
}
227
249
}
@@ -672,7 +694,8 @@ public static function snake(string $value, string $delimiter = '_'): string
672
694
public static function startsWith (string $ haystack , $ needles ): bool
673
695
{
674
696
foreach ((array ) $ needles as $ needle ) {
675
- if ($ needle !== '' && str_starts_with ($ haystack , (string ) $ needle )) {
697
+ $ needle = (string ) $ needle ;
698
+ if ($ needle !== '' && str_starts_with ($ haystack , $ needle )) {
676
699
return true ;
677
700
}
678
701
}
0 commit comments