From 07f2dcd989a517cdc60497fabcca58b91a13a7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 20 Jul 2025 01:07:20 +0200 Subject: [PATCH 1/2] consistent use of mb_split to split strings into words with multi-byte support --- src/Illuminate/Support/Str.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 764acf47fc5b..7e833c1be87b 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1449,7 +1449,7 @@ public static function title($value) */ public static function headline($value) { - $parts = explode(' ', $value); + $parts = mb_split('/\s+/', $value); $parts = count($parts) > 1 ? array_map(static::title(...), $parts) @@ -1482,7 +1482,7 @@ public static function apa($value) $endPunctuation = ['.', '!', '?', ':', '—', ',']; - $words = preg_split('/\s+/', $value, -1, PREG_SPLIT_NO_EMPTY); + $words = mb_split('/\s+/', $value); for ($i = 0; $i < count($words); $i++) { $lowercaseWord = mb_strtolower($words[$i]); @@ -1697,7 +1697,7 @@ public static function studly($value) return static::$studlyCache[$key]; } - $words = explode(' ', static::replace(['-', '_'], ' ', $value)); + $words = mb_split('/\s+/', static::replace(['-', '_'], ' ', $value)); $studlyWords = array_map(fn ($word) => static::ucfirst($word), $words); From d8a358f89f3e9f6a7702072dd7f3db2d0a9a7581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 20 Jul 2025 01:37:19 +0200 Subject: [PATCH 2/2] The $pattern argument doesn't use /pattern/ delimiters, unlike other regex functions such as preg_match --- src/Illuminate/Support/Str.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 7e833c1be87b..ffe670f6f9c5 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1449,7 +1449,7 @@ public static function title($value) */ public static function headline($value) { - $parts = mb_split('/\s+/', $value); + $parts = mb_split('\s+', $value); $parts = count($parts) > 1 ? array_map(static::title(...), $parts) @@ -1482,7 +1482,7 @@ public static function apa($value) $endPunctuation = ['.', '!', '?', ':', '—', ',']; - $words = mb_split('/\s+/', $value); + $words = mb_split('\s+', $value); for ($i = 0; $i < count($words); $i++) { $lowercaseWord = mb_strtolower($words[$i]); @@ -1697,7 +1697,7 @@ public static function studly($value) return static::$studlyCache[$key]; } - $words = mb_split('/\s+/', static::replace(['-', '_'], ' ', $value)); + $words = mb_split('\s+', static::replace(['-', '_'], ' ', $value)); $studlyWords = array_map(fn ($word) => static::ucfirst($word), $words);