symfony/polyfill-mbstring
Provides a partial native PHP polyfill for the mbstring extension, supplying multibyte string functions when mbstring isn’t installed. Part of Symfony’s Polyfill set; lightweight and MIT-licensed.
The symfony/polyfill-mbstring package provides a drop-in replacement for PHP’s mbstring extension, ensuring consistent multibyte string handling across environments—even when ext-mbstring is not installed (e.g., minimal Docker images, shared hosting).
Start here:
composer require symfony/polyfill-mbstring.mb_* functions as usual (e.g., mb_strlen(), mb_substr(), mb_convert_encoding()). The polyfill auto-initializes on first use.ext-mbstring.strlen()/substr() with mb_strlen()/mb_substr() throughout legacy code or new projects to avoid byte-oriented string bugs (e.g., in UTF-8 text).ext-mbstring may be disabled to catch encoding-related bugs early.ext-mbstring is available at runtime (extension_loaded('mbstring')). If so, you could conditionally skip the polyfill (though it’s safe and often faster than disabling manually due to internal optimizations).iconv: The polyfill depends on ext-iconv. If iconv is missing (e.g., Alpine Linux containers), mb_* calls may fail. Ensure php-iconv is installed.mbstring functions—rare ones like mb_http_output() or mb_internal_encoding() work, but edge-case locale-sensitive behaviors may differ slightly. Always check function availability if relying on obscure features.mbstring.func_overload equivalence: PHP’s mbstring.func_overload directive is ignored. The polyfill does not override core functions (strlen, strpos, etc.)—only provides mb_* versions.mb_internal_encoding() to confirm encoding isn’t silently defaulting to ISO-8859-1. Explicitly set mb_internal_encoding('UTF-8') at app bootstrap.How can I help you explore Laravel packages today?