symfony/polyfill-intl-idn
Provides polyfills for PHP’s Intl IDN functions idn_to_ascii and idn_to_utf8, enabling internationalized domain name conversion on systems where the Intl extension isn’t available. Part of Symfony’s Polyfill components, MIT licensed.
Install the package via Composer:
composer require symfony/polyfill-intl-idn
It’s automatically autoloaded—no manual setup or config required. The polyfill registers idn_to_ascii() and idn_to_utf8() functions globally only if they don’t already exist (i.e., when ext-intl is absent).
First use case: Sanitize user-submitted international domains for storage or validation:
$domain = idn_to_ascii('москва.рф');
// → 'xn--80acaazcfs.xn--p1ai'
idn_to_ascii()/idn_to_utf8() directly anywhere—no namespace imports. Works identically to ext-intl when available.$normalized = idn_to_ascii($input['domain'] ?? '');
if ($normalized === false) {
// Handle invalid domain
}
idn_to_ascii() for storage/comparison and idn_to_utf8() for UI display—ensures both safety and readability:
$ascii = idn_to_ascii($domain); // Stored in DB
$ui = idn_to_utf8($ascii); // Shown in profile view
filter_var(..., FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) after ASCII conversion for robust RFC-compliant validation.idn_to_ascii() returns false and triggers E_WARNING on invalid input (e.g., malformed labels). Use @idn_to_ascii() or check intl_get_error_code() (if ext-intl is present) for graceful handling.IDNA_DEFAULT) may not suit all cases. For email addresses (RFC 6142), explicitly set flags:
idn_to_ascii('test@café.com', IDNA_CHECK_BIDI | IDNA_NONTRANSITIONAL_TO_ASCII);
symfony/polyfill-intl-normalizer. Composer handles this automatically—verify composer.lock isn’t stale if IDN calls fail silently.ext-intl-enabled environments, include the polyfill for consistency across dev/staging/prod (avoids "works on my machine" edge cases). The polyfill safely self-deactivates if native functions exist.How can I help you explore Laravel packages today?