PHP 8.0.26 Released!


(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.2, PECL idn >= 0.1)




    string $domain,
    int $flags = IDNA_DEFAULT,
    int $variant = INTL_IDNA_VARIANT_UTS46,
    array &$idna_info = null
): string|false

Unicode のドメイン名を、IDNAが定めたASCII形式に変換します。



変換するドメイン名。UTF-8 にエンコードされている必要があります。


変換オプション - IDNA_ ではじまる定数 (IDNA_ERROR_* 定数を除く) の組み合わせです。


IDNA 2003 の場合は INTL_IDNA_VARIANT_2003 (PHP 7.2.0 以降は非推奨)、あるいは UTS #46 の場合は INTL_IDNA_VARIANT_UTS46 (ICU 4.6 以降のみ利用可能)。


このパラメータを使うのは、variantINTL_IDNA_VARIANT_UTS46 の場合だけです。 このとき、このパラメータには 'result''isTransitionalDifferent'、そして 'errors' の三つのキーを含む配列が入ります。 'result' にはおそらく不正だと考えられる変換結果、 'isTransitionalDifferent' には UTS #46 の非移行的な機能を使って結果を変更したかどうかをあらわす boolean 値、そして 'errors' はエラー定数 IDNA_ERROR_* のビットセットを表します。


IDNA のASCII形式でエンコードされたドメイン名。失敗した場合に false を返します


バージョン 説明
7.4.0 variant のデフォルト値が INTL_IDNA_VARIANT_UTS46 となり、 その代わりに INTL_IDNA_VARIANT_2003 は非推奨となりました。
7.2.0 INTL_IDNA_VARIANT_2003 は非推奨です。代わりに INTL_IDNA_VARIANT_UTS46 を使用してください。

例1 idn_to_ascii() の例


echo idn_to_ascii(''); 




  • idn_to_utf8() - IDNAのASCII方式でエンコードされたドメイン名をUnicodeに変換する

add a note

User Contributed Notes 3 notes

edible dot email at gmail dot com
10 years ago
The notes on this function are not very clear and a little misleading.

Firstly, <=5.3, you will need to make use of one of several scripts or classes available on the internet which might, or might not, require the installation of of the intl and idn PECL extensions ...and you will need to have !<4.0 in order to be able to install both.

Secondly, if you have >=5.4 you will not require the PECL extensions.

Third, use of utf8_encode() is not necessary.  In fact, it will potentially prevent idn_to_ascii() from working at all.

On my setup it was necessary to change the charset in the script meta tags to UTF-8:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

...and to change charset_default in the php.ini file (/usr/local/lib/php.ini, whereis php.ini, find / -name php.ini):

default_charset = "UTF-8"

The above changes mean that idn_to_ascii() can now be used with that syntax (no need for utf8_encode()).  Previously, the function worked to convert some IDNs, but failed to convert Japanese and Cyrillic IDNs.  Further, no additional locales were enabled or added, and Apache's charset file was left unmodified.

It is also important to remember only to apply the function where required, eg:

idn_to_ascii(cå // is wrong


iden_to_ascii(cåsino) // is right

...and also be aware of text editors that don't support UTF-8 encoding, or the $domain = 'cåsino' value will end up as $domain = '??????' ...and the function will fail.

I have found that Notepad++ easily and reliably handles UTF-8 encoding that works for this function using UTF-8 as the encoding option, not UTF-8 without BOM.
mschrieck at gmail dot com
5 years ago
To convert IDN Domains with the IDNA2008 definition use following command.


The result is then as expected
waxblur at gmx dot at
2 years ago
In Windows, the path to the PHP folder must still be present in the PATH environment variable, becouse the necessary DLLs (icudt65.dll, icuin65.dll etc.) are available in this folder.
To Top