Skip to content

Commit c1dc239

Browse files
shaedrichGrahamCampbell
authored andcommitted
[12.x] Consistent use of mb_split() to split strings into words (#56338)
* consistent use of mb_split to split strings into words with multi-byte support * The $pattern argument doesn't use /pattern/ delimiters, unlike other regex functions such as preg_match
1 parent b049180 commit c1dc239

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
@@ -1402,7 +1402,7 @@ public static function title($value)
14021402
*/
14031403
public static function headline($value)
14041404
{
1405-
$parts = explode(' ', $value);
1405+
$parts = mb_split('\s+', $value);
14061406

14071407
$parts = count($parts) > 1
14081408
? array_map([static::class, 'title'], $parts)
@@ -1435,7 +1435,7 @@ public static function apa($value)
14351435

14361436
$endPunctuation = ['.', '!', '?', ':', '', ','];
14371437

1438-
$words = preg_split('/\s+/', $value, -1, PREG_SPLIT_NO_EMPTY);
1438+
$words = mb_split('\s+', $value);
14391439

14401440
for ($i = 0; $i < count($words); $i++) {
14411441
$lowercaseWord = mb_strtolower($words[$i]);
@@ -1638,7 +1638,7 @@ public static function studly($value)
16381638
return static::$studlyCache[$key];
16391639
}
16401640

1641-
$words = explode(' ', static::replace(['-', '_'], ' ', $value));
1641+
$words = mb_split('\s+', static::replace(['-', '_'], ' ', $value));
16421642

16431643
$studlyWords = array_map(fn ($word) => static::ucfirst($word), $words);
16441644

0 commit comments

Comments
 (0)