symfony/polyfill-intl-grapheme
Native PHP polyfill for the Intl Grapheme functions, for working with UTF-8 grapheme clusters. Provides grapheme_strlen, grapheme_substr, grapheme_strpos/stripos, grapheme_extract, grapheme_str_split, and related helpers when ext-intl isn’t available.
Search & Recommendation Systems (Enhanced Stability):
grapheme_str_split() breaks on complex regex patterns (e.g., Arabic with diacritics or emoji clusters).Legacy System Modernization (Risk Mitigation):
grapheme_str_split() returns incorrect splits for strings like "مدم👨👩👧👦" on PCRE 8, which could break RTL text processing pipelines.Developer Experience (DX) Improvements (Debugging):
grapheme_str_split() to fail on specific regex patterns, improving reliability for:
grapheme_str_split() (e.g., Str::graphemeWords()).PHP 8.6+ Migration Strategy (Future-Proofing):
grapheme_strrev()/grapheme_str_split() in new Laravel 11+ projects.Text Games & Validation (Accuracy):
grapheme_str_split() works correctly for multilingual word games (e.g., splitting "مدم" into ["م", "د", "م"] without PCRE-induced errors).grapheme_str_split() for:
"👨👩👧👦" → ["👨👩👧👦"])."éléphant" → ["é", "l", "é", "p", "h", "a", "n", "t"]).grapheme_str_split() fails silently.str_split/preg_split hacks to a maintained polyfill.grapheme_str_split() works out-of-the-box).str_split or preg_split).preg_split with ASCII patterns.symfony/polyfill-intl-normalizer for advanced grapheme handling (e.g., NFKC normalization + splitting).IntlGraphemeClusterIterator-based splitter (slower but no dependencies).str_split or preg_split('/./u') for ASCII/UTF-8 strings without combining characters.*"This tiny fix (v1.38.1) eliminates a silent bug that could break RTL language features for millions of users—especially on shared hosting. Here’s why it matters:
grapheme_str_split() fails on PCRE 8 (common in older PHP stacks).composer update symfony/polyfill-intl-grapheme) fixes a regression that could silently corrupt text processing.Example Impact:
Ask: Should we proactively update this dependency to avoid future RTL/emoji bugs? Cost: 5 minutes. ROI: 10x for global markets."
*"v1.38.1 fixes a critical edge case in grapheme_str_split() when running on PCRE 8 (common in older PHP/hosting environments). Here’s how it affects you:
grapheme_str_split() now works correctly with PCRE 8 regex patterns, preventing silent failures for:
composer update symfony/polyfill-intl-grapheme
use Symfony\Component\Polyfill\Intl\Grapheme\StringHelper;
$split = StringHelper::strSplit("مدم👨👩👧👦", 1);
// Now returns: ["م", "د", "م", "👨👩👧👦"] (correct)
Str helper for grapheme-aware splitting:
Str::macro('graphemeWords', fn($string, $limit = null) =>
collect(grapheme_str_split($string, $limit))
);
{{ Str::graphemeWords($userInput, 3) }}
| Feature | Risk Without Fix | Solution |
|---|---|---|
| RTL Search Indexing | Silent failures splitting Arabic tokens | grapheme_str_split() now works on PCRE 8. |
| Emoji Chat Messages | Emoji clusters split into invalid parts | Correctly splits 👨👩👧👦 as one unit. |
| Text Games (Anagrams) | Persian/Arabic words split incorrectly | Accurate grapheme-aware splitting. |
| Legacy Laravel Apps | Custom preg_split hacks break on PCRE 8 |
Drop-in replacement for grapheme_str_split. |
| Elasticsearch Analyzers | Tokenization fails for RTL languages | Reliable grapheme splitting for search. |
str_split for ASCII; use only for Unicode.Action: Update the package now if you:
How can I help you explore Laravel packages today?