Skip to content

Commit 816ffa5

Browse files
authored
[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 488cbf5 commit 816ffa5

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
@@ -1449,7 +1449,7 @@ public static function title($value)
14491449
*/
14501450
public static function headline($value)
14511451
{
1452-
$parts = explode(' ', $value);
1452+
$parts = mb_split('\s+', $value);
14531453

14541454
$parts = count($parts) > 1
14551455
? array_map(static::title(...), $parts)
@@ -1482,7 +1482,7 @@ public static function apa($value)
14821482

14831483
$endPunctuation = ['.', '!', '?', ':', '', ','];
14841484

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

14871487
for ($i = 0; $i < count($words); $i++) {
14881488
$lowercaseWord = mb_strtolower($words[$i]);
@@ -1697,7 +1697,7 @@ public static function studly($value)
16971697
return static::$studlyCache[$key];
16981698
}
16991699

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

17021702
$studlyWords = array_map(fn ($word) => static::ucfirst($word), $words);
17031703

0 commit comments

Comments
 (0)