@@ -183,10 +183,32 @@ public static function charAt($subject, $index)
183183 *
184184 * @param array|string $needles
185185 */
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
187208 {
188209 foreach ((array ) $ needles as $ needle ) {
189- if ($ needle !== '' && str_contains ($ haystack , (string ) $ needle )) {
210+ $ needle = (string ) $ needle ;
211+ if ($ needle !== '' && stripos ($ haystack , $ needle ) !== false ) {
190212 return true ;
191213 }
192214 }
@@ -197,14 +219,13 @@ public static function contains(string $haystack, $needles): bool
197219 /**
198220 * Determine if a given string contains all array values.
199221 *
200- * @param string $haystack
201222 * @param string[] $needles
202223 * @return bool
203224 */
204- public static function containsAll ($ haystack , array $ needles )
225+ public static function containsAll (string $ haystack , array $ needles, bool $ ignoreCase = false )
205226 {
206227 foreach ($ needles as $ needle ) {
207- if (! static ::contains ($ haystack , $ needle )) {
228+ if (! static ::contains ($ haystack , $ needle, $ ignoreCase )) {
208229 return false ;
209230 }
210231 }
@@ -221,7 +242,8 @@ public static function containsAll($haystack, array $needles)
221242 public static function endsWith (string $ haystack , $ needles )
222243 {
223244 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 )) {
225247 return true ;
226248 }
227249 }
@@ -672,7 +694,8 @@ public static function snake(string $value, string $delimiter = '_'): string
672694 public static function startsWith (string $ haystack , $ needles ): bool
673695 {
674696 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 )) {
676699 return true ;
677700 }
678701 }
0 commit comments