Skip to content

Commit 331e53a

Browse files
authored
[9.x] PHP8 string functions for Str class (#38011)
* use str_contains over mb_strpos * use str_ends_with over substr * use str_starts_with over strncmp
1 parent 7bfc315 commit 331e53a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Illuminate/Support/Str.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static function contains($haystack, $needles, $ignoreCase = false)
187187
}
188188

189189
foreach ((array) $needles as $needle) {
190-
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
190+
if ($needle !== '' && str_contains($haystack, $needle)) {
191191
return true;
192192
}
193193
}
@@ -231,7 +231,7 @@ public static function endsWith($haystack, $needles)
231231
foreach ((array) $needles as $needle) {
232232
if (
233233
$needle !== '' && $needle !== null
234-
&& substr($haystack, -strlen($needle)) === (string) $needle
234+
&& str_ends_with($haystack, $needle)
235235
) {
236236
return true;
237237
}
@@ -763,7 +763,7 @@ public static function snake($value, $delimiter = '_')
763763
public static function startsWith($haystack, $needles)
764764
{
765765
foreach ((array) $needles as $needle) {
766-
if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) {
766+
if ((string) $needle !== '' && str_starts_with($haystack, $needle)) {
767767
return true;
768768
}
769769
}

0 commit comments

Comments
 (0)