symfony/polyfill-intl-grapheme
Symfony polyfill for Intl Grapheme functions (grapheme_*): provides consistent multibyte-safe string length, substring, and position operations when the intl extension isn’t available. Useful for Unicode-aware text handling across PHP versions.
This polyfill provides grapheme_* functions (e.g., grapheme_strlen, grapheme_substr, grapheme_strpos) for environments where the intl extension is not installed or is incomplete. Start by installing it via Composer:
composer require symfony/polyfill-intl-grapheme
Once installed, it automatically patches the grapheme_* functions at runtime — no configuration required. Your first use case is likely safely handling multi-byte Unicode grapheme clusters (e.g., emoji, accented characters) in strings, especially when migrating from or supporting servers without intl.
strlen, substr, strpos, etc.) with their grapheme_* equivalents only where needed (e.g., user input processing, UI display logic, database sanitization).// Count visible characters in "A̐éö" (3 graphemes, 5 codepoints)
$len = grapheme_strlen("A̐éö"); // → 3
if (!function_exists('grapheme_strlen')) {
require_once __DIR__ . '/vendor/symfony/polyfill-intl-grapheme/bootstrap.php';
}
AppServiceProvider or use Laravel’s built-in polyfill support. Many Laravel string helpers (e.g., Str::length()) automatically benefit from it when intl is unavailable.Intl fallback: Unlike other Symfony polyfills, this one only provides the grapheme_* functions — it does not add intl coverage elsewhere. Ensure you’re not conflating it with symfony/polyfill-intl-normalizer or symfony/polyfill-intl-icu.xdebug.show_exception_trace = 0 if you see cryptic errors — polyfills sometimes interact poorly with Xdebug’s stack tracing.intl is installed but outdated (e.g., missing grapheme_* in older PHP versions), the polyfill will still activate. Check function_exists('grapheme_strlen') at runtime if needed."flag 🏳️🌈", "é + combining acute") to catch grapheme-related regressions.How can I help you explore Laravel packages today?