idn_to_ascii

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

idn_to_asciiAlan adını IDNA ASCII biçimine dönüştürür

Açıklama

Yordamsal kullanım

idn_to_ascii(
    string $alan,
    int $seçenekler = IDNA_DEFAULT,
    int $varyant = INTL_IDNA_VARIANT_UTS46,
    array &$idna_info = null
): string|false

Unicode alan adını IDNA ASCII kodlu alan adına dönüştürür.

Bağımsız Değişkenler

alan

Dönüştürülecek alan adı. UTF-8 kodlu olmalıdır.

seçenekler

IDNA_* sabitlerinden oluşan dönüşüm seçenekleri. (IDNA_ERROR_* sabitleri hariç)

varyant

Ya IDNA 2003 için INTL_IDNA_VARIANT_2003 (kullanımı PHP 7.2.0 itibariyle önerilmiyor) ya da UTS #46 için INTL_IDNA_VARIANT_UTS46 (sadece ICU 4.6 ve üstü ile kullanılabilir).

idna_info

Bu bağımsız değişken sadece varyant için INTL_IDNA_VARIANT_UTS46 kullanılmışsa kullanılabilir. Bu durumda, muhtemelen meşru olmayan bir dönüşümün sonucu olarak 'result', sonucu değiştirmiş ya da değiştirecek olan UTS #46'nın geçiş mekanizmalarının kullanımının değişip değişmediğini gösteren bir mantıksal değer olarak 'isTransitionalDifferent' ve IDNA_ERROR_* hata sabitlerinin bir bit kümesini temsil eden birer tamsayı olarak 'errors' anahtarlı bir dizi ile doldurulur.

Dönen Değerler

ASCII uyumlu kodlanmış alan adı, başarısızlık durumunda false döner.

Sürüm Bilgisi

Sürüm: Açıklama
7.4.0 varyant bağımsız değişkeninin öntanımlısı artık INTL_IDNA_VARIANT_UTS46 oldu; evvelce INTL_IDNA_VARIANT_2003 idi ve kulllanımı önerilmiyordu.
7.2.0 INTL_IDNA_VARIANT_2003 sabitinin kulllanımı artık önerilmiyor; yerine INTL_IDNA_VARIANT_UTS46 kullanılmalıdır.

Örnekler

Örnek 1 - idn_to_ascii() örneği

<?php

echo idn_to_ascii('täst.de');

?>

Yukarıdaki örneğin çıktısı:

xn--tst-qla.de

Ayrıca Bakınız

  • idn_to_utf8() - Alan adı kodlamasını IDNA ASCII'den UTF-8'e dönüştürür

add a note add a note

User Contributed Notes 3 notes

up
15
edible dot email at gmail dot com
11 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åsino.com) // is wrong

...whereas...

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.
up
8
mschrieck at gmail dot com
6 years ago
To convert IDN Domains with the IDNA2008 definition use following command.

idn_to_ascii('teßt.com',IDNA_NONTRANSITIONAL_TO_ASCII,INTL_IDNA_VARIANT_UTS46)

The result is then as expected

xn--tet-6ka.com
up
0
waxblur at gmx dot at
3 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