PHP – idn_to_ascii() function

The idn_to_ascii() function in PHP is used to convert a Unicode domain name into IDNA ASCII form. IDNA stands for Internationalizing Domain Names in Applications. It is a mechanism for handling internationalized domain names containing nonASCII characters.


string idn_to_ascii(
   str $domain,
   integer $flags=IDNA_DEFAULT,
   integer $variant=INTL_IDNA_VARIANT_UTS46,
   arr &$idna_info=null


idn_to_ascii() accepts the following four parameters −

  • $domain − This is the domain to be converted; it must be UTF-8 encoded.

  • $flags − This parameter is a combination of IDNA_*constants.

  • $variant − This parameter uses either INTL_IDNA_VARIANT_2003 for IDNA 2003 or INTL_IDNA_VARIANT_UTS46 for UTS#46.

  • $idna_info − This parameter is used only if the INTL_IDNA_VARIANT_UTS46 is used in the $variant parameter.

Return Values

This function returns the domain name encoded in ASCII-compatible form, or it returns False on failure.

Example 1

   // String domain
   print idn_to_ascii('tä',0);


Example 2

   // encoded string ISO-8859-2
   echo idn_to_ascii(utf8_encode('tä'));

   // It cannot convert a domain name to ASCII
   // that contains non-ASCII chars but
   // it already start with "xn--"
   $ascii = idn_to_ascii("xn--".chr(0xC3).chr(0xA4));


Updated on: 12-Oct-2021


Kickstart Your Career

Get certified by completing the course

Get Started