symfony/polyfill-intl-grapheme
Native PHP polyfill for Intl Grapheme functions when ext-intl isn’t available. Works with UTF-8 strings and provides grapheme-aware length, substring, splitting, extraction, and case-sensitive/insensitive position and search functions.
Globalization & Localization (G11N/L10N) Expansion:
PHP 8.6+ Migration and Future-Proofing:
grapheme_strrev() is available. Reduces dependency on the intl extension, which may not be available in all hosting environments (e.g., shared hosting).Search and Recommendation Systems:
Developer Experience (DX) and Consistency:
Str helper with grapheme-aware methods (e.g., Str::graphemeReverse()), reducing cognitive load and ensuring consistency across the codebase.Legacy System Modernization:
intl extension is unavailable.reverseArabicString() with the standardized grapheme_strrev() polyfill.Text Games, Validation, and Security:
strrev fails for grapheme clusters.intl extension, needing grapheme-aware strrev.strrev logic for non-ASCII strings with a maintained polyfill.strrev).intl Extension Available: Using PHP 8.6+ with the intl extension enabled (prefer IntlGraphemeClusterIterator for full Unicode support).strrev suffices.strrev or precomputed reversals may be faster.grapheme_strrev() function requires PHP 8.6+ (no polyfill fallback for older versions).symfony/polyfill-intl-normalizer for advanced grapheme handling (e.g., NFKC normalization).grapheme_strrev from ext/intl if available, or implement a custom fallback (e.g., using IntlGraphemeClusterIterator).strrev is sufficient for ASCII-only use cases.intl extension or custom solutions.*"This update unlocks seamless RTL language support and emoji/Unicode correctness in our Laravel applications—critical for global markets where 80% of text isn’t English. Here’s why it matters:
intl extension, reducing hosting costs and dependency risks.Investment: Minimal—one sprint to integrate. ROI: 10x for RTL markets (e.g., Middle East, North Africa). Competitors using ASCII-only strrev will lag behind in UX and functionality.
Example: A user searches for ‘مدم’ in our app. Our autocomplete matches it correctly, while competitors’ tools fail. This is a game-changer for adoption in RTL regions."*
*"The symfony/polyfill-intl-grapheme package adds grapheme-aware string reversal to Laravel, solving critical issues for RTL languages and Unicode edge cases. Here’s how to use it:
grapheme_strrev() without requiring the intl extension.composer require symfony/polyfill-intl-grapheme:^1.37
Str Helper:
Str::macro('graphemeReverse', fn($string) => grapheme_strrev($string));
// PHP
$reversed = Str::graphemeReverse("مدم"); // Returns "مدم" (correct RTL reversal)
// Blade
{{ Str::graphemeReverse($userInput) }}
| Feature | Implementation | Example |
|---|---|---|
| RTL Autocomplete | Reverse query for grapheme-aware matching | Match ‘مدم’ to ‘مدم’ in search. |
| Text Games | Palindrome/anagram validation | Detect ‘مدم’ as a palindrome. |
| CMS Previews | Reverse RTL text for WYSIWYG | Show Arabic text correctly in previews. |
| Emoji Support | Reverse emoji clusters | Reverse ‘👨👩👧 |
How can I help you explore Laravel packages today?