symfony/polyfill-iconv
Provides an iconv-compatible API for PHP, ensuring consistent character set conversion and transliteration across environments. Part of Symfony Polyfill, it helps apps run reliably when the native iconv extension is missing or behaves differently on some systems.
Install the polyfill via Composer—no further configuration required:
composer require symfony/polyfill-iconv
It auto-registers via Composer’s autoloader and activates transparently when iconv_* functions are called and ext-iconv isn’t loaded. First use case: confirm polyfill is active in development or CI where ext-iconv is omitted:
// In a script or test
$hasIconvExt = extension_loaded('iconv');
$polyfillLoaded = class_exists('Symfony\Polyfill\Iconv\Iconv');
if (!$hasIconvExt && $polyfillLoaded) {
$converted = iconv('UTF-8', 'ASCII//IGNORE', 'Zürich'); // → "Zrich"
echo $converted; // Verify behavior
}
iconv() and related functions (iconv_strlen, iconv_substr, iconv_mime_encode) identically to native — no wrapper or adapter needed. Ideal for refactoring legacy code or running third-party libraries expecting iconv.symfony/polyfill-mbstring to cover all multibyte string operations in environments where neither ext-iconv nor ext-mbstring are guaranteed (e.g., shared hosting, lightweight containers).require-dev only if strict environment control is needed, but production use is safest for portability (e.g., Laravel apps deployed to Heroku, Docker, or AWS Lambda with minimal PHP builds).files autoloading (as defined in vendor/symfony/polyfill-iconv/composer.json).//TRANSLIT uses basic ASCII fallbacks (e.g., é → e), but complex scripts (Arabic, Thai, CJK) may render incorrectly. //IGNORE is robust, but verify with your target locales.iconv_get_encoding() Unavailable: This function isn’t polyfilled—use iconv('UTF-8', 'UTF-8', $str) or mb_internal_encoding() to verify encoding context instead.ext-iconv is present, the polyfill won’t override it (PHP extensions take precedence). To force polyfill for testing: php -d extension=-iconv artisan test.// In app/Http/Middleware/PolyfillMonitor.php
if (!extension_loaded('iconv') && class_exists(\Symfony\Polyfill\Iconv\Iconv::class)) {
\Log::info('Polyfill iconv in use');
}
How can I help you explore Laravel packages today?