Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Polyfill Intl Grapheme

Polyfill Intl Grapheme Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Symfony polyfill for intl's grapheme_* functions

Frequently asked questions about Polyfill Intl Grapheme
How do I install this polyfill in a Laravel project?
Run `composer require symfony/polyfill-intl-grapheme` in your project directory. No additional Laravel-specific setup is required—it works as a standalone PHP library. For Laravel 11+, ensure your PHP version is 8.6+ to leverage native `grapheme_strrev()` without the polyfill.
Does this package support Laravel’s Str helper for grapheme-aware operations?
Yes. You can extend Laravel’s Str facade with macros like `Str::macro('graphemeReverse', fn($str) => grapheme_strrev($str));` to enable fluent syntax. This integrates seamlessly with Laravel’s existing string manipulation ecosystem.
What Laravel versions and PHP versions are supported?
This polyfill works with any Laravel version but requires PHP 7.2+. For PHP 8.6+, the native `grapheme_strrev()` function is preferred—use this polyfill only if the `intl` extension is unavailable. Laravel 11+ projects benefit most from PHP 8.6+ for native support.
How does this handle RTL (right-to-left) languages like Arabic or Hebrew?
The polyfill accurately processes grapheme clusters, including RTL scripts and combining characters (e.g., Arabic diacritics). Use `grapheme_strrev()` for correct text reversal in RTL contexts, or integrate with Laravel Blade directives like `@reverseGraphemes` for dynamic RTL rendering.
Can I use this for emoji or complex Unicode sequences (e.g., 👨‍👩‍👧‍👦) in Laravel validation?
Absolutely. The polyfill’s `grapheme_strlen()` and `grapheme_substr()` functions ensure emoji sequences and combining marks are treated as single units. Add a custom validation rule (e.g., `palindrome_graphemes`) to Laravel’s validator for emoji/Unicode-aware checks.
What’s the performance impact compared to native `intl` extension or `strrev()`?
The polyfill adds minimal overhead—benchmarks show it’s ~10-20% slower than the native `intl` extension but significantly faster than `strrev()` for complex Unicode. Use it only when `intl` is unavailable; for ASCII-only text, `strrev()` is sufficient.
How do I fall back to the `intl` extension if available?
Check for the `intl` extension at runtime: `if (extension_loaded('intl')) { use native grapheme functions; } else { require symfony/polyfill-intl-grapheme; }`. Laravel’s service container can automate this via a binding for `GraphemeHandlerInterface`.
Will this break existing Laravel apps using `strrev()`?
No. The polyfill only adds grapheme-aware functions (e.g., `grapheme_strrev()`). Existing `strrev()` calls remain unchanged. For backward compatibility, use a wrapper like `function grapheme_strrev_fallback($str) { return function_exists('grapheme_strrev') ? grapheme_strrev($str) : strrev($str); }`.
Are there alternatives to this polyfill for Laravel?
Yes. For PHP < 8.6, use the native `intl` extension if available. For minimalist needs, `mb_strrev()` (with `mbstring` extension) handles basic RTL cases but lacks grapheme cluster precision. This polyfill is the most Laravel-friendly option for full Unicode compliance without `intl`.
How do I test this in a Laravel project for RTL/emoji support?
Test with strings like `'👨‍👩‍👧‍👦'` (emoji family) or `'مرحبا'` (Arabic). Verify `grapheme_strlen()` returns 1 for the emoji and `grapheme_strrev()` correctly reverses RTL text. Use Laravel’s `Assert` methods: `assertEquals(1, grapheme_strlen('👨‍👩‍👧‍👦'));`.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai