Internationalized Domain Names in Applications (IDNA)

De Bricosoft.

Internationalized Domain Names in Applications (IDNA) xn--a-5fa xn--pte-6la (ça pète) ! Non ?

Sommaire

[modifier] PHP

[modifier] soucis d'encodage

  • � caractère inconnu, votre texte est probablement encore ISO, essayez utf8_encode()
  • é encodé une 2eme fois, votre texte est déjà UTF, pas la peine d'en rajouter (c)Maxwell qualité filtre

[modifier] idn.so

L'extension idn est un wrap de la bilbliothèque GNU libidn11 (ici version 1.1) :

$ aptitude show libidn11
...
Description : GNU libidn library, implementation of IETF IDN specifications
GNU Libidn is an implementation of the Stringprep, Punycode and IDNA
specifications defined by the IETF Internationalized Domain Names (IDN) working
group, used for internationalized domain names. Currently the Nameprep,
Kerberos 5 and XMPP Stringprep profiles are supported.
Site : http://www.gnu.org/software/libidn/

Pour l'installer :

# apt-get install libidn11 libidn11-dev

Vous avez maintenant une commande bien pratique : idn

  • l'option -a vous sort la chaine ACE (punycode avec le préfixe xn--) :
$ idn --quiet -a 自助软
xn--7frp31iyqi 
  • l'option -d vous décode le punycode :
$ idn --quiet -d bb-bjab
bébé
  • l'option -u vous décode l'ACE :
$ idn --quiet -u xn--bb-bjab
bébé
  • l'option --debug permet de récupérer le codage en héxadécimal de chaque caractères (chaine paramètre et résultat)
Une xn--dliceuse-b1a xn--hxaj1agpydl xn--0ca xn--dguster-bya !
 $ idn --quiet -a --debug μουσακάς
Jeu de caractères `UTF-8'.
input[0] = U+03bc
input[1] = U+03bf
input[2] = U+03c5
input[3] = U+03c3
input[4] = U+03b1
input[5] = U+03ba
input[6] = U+03ac
input[7] = U+03c2
tld[0] = U+03bc
tld[1] = U+03bf
tld[2] = U+03c5
tld[3] = U+03c3
tld[4] = U+03b1
tld[5] = U+03ba
tld[6] = U+03ac
tld[7] = U+03c3
output[0] = U+0078
output[1] = U+006e
output[2] = U+002d
output[3] = U+002d
output[4] = U+0068
output[5] = U+0078
output[6] = U+0061
output[7] = U+006a
output[8] = U+0031
output[9] = U+0061
output[10] = U+0067
output[11] = U+0070
output[12] = U+0079
output[13] = U+0064
output[14] = U+006c
xn--hxaj1agpydl

Miam ! une bonne xn--hxaj1agpydl chaude :o)~~

Ensuite il vous faut l'extension PHP depuis PECL, si vous n'avez pas la commande pecl (ni phpize) :

# apt-get install php5-pear php5-dev

L'extension :

$ sudo pecl install idn

Si l'erreur suivante apparaît :

Failed to download pecl/idn within preferred state "stable", latest release is version 0.2.0, stability "beta", use "channel://pecl.php.net/idn-0.2.0" to install
Cannot initialize 'channel://pecl.php.net/idn', invalid or missing package file
Package "channel://pecl.php.net/idn" is not valid
install failed

C'est écrit dessus, comme le Port-salut, alors :

$ sudo pecl install idn-0.2.0
...
Build process completed successfully
...
configuration option "php_ini" is not set to php.ini location
You should add "extension=idn.so" to php.ini

Comme indiqué par le monsieur dedans l'ordinateur, rajoutez dans /etc/php5/apache2/php.ini :

extension=idn.so

sous la section :

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

Rechargez Apache :

$ sudo /etc/init.d/apache2 reload

Vérifiez dans votre phpinfo() que vous avez bien une nouvelle section "idn".

Et voilà vous avez ces nouvelles fonctions PHP :

$puny= idn_to_ascii('自助软');
...
$uni= idn_to_utf8('xn--7frp31iyqi');

[modifier] Liens

[modifier] PEAR Net_IDNA

$ sudo pear install net_idna-0.7.3
require 'Net/IDNA.php';
 
$oIdn = Net_IDNA::getInstance();
 
$sPunyCode= $idn->encode('自助软');
$sUnicode= $idn->decode('xn--7frp31iyqi');

[modifier] Liens

[modifier] Librairies alternatives

[modifier] Phlymail IDNA

[modifier] Liens


Plus