Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

idn_to_ascii() in 5.2.17

Tags:

php

utf

dns

idn

There's a very handy function idn_to_ascii() in PHP 5.3, but I'm running 5.2.17 and I can't change that. How do I encode Unicode domain names to ascii then?

like image 536
donk Avatar asked Mar 23 '11 12:03

donk


2 Answers

Peter's answer gives you the official IDN functions in PHP 5.2, and if possible it's probably the best answer.

However some users will be unable to install a PECL library on their PHP system, so they would need to have a conversion library written in plain PHP which they can just include within their own code.

Fortunately there is a solution: http://phlymail.com/en/downloads/idna/

This is a PHP class which allows you to encode and decode between unicode and punycode. Very simple to use and doesn't require any kind of installing (other than downloading and including into your own PHP code).

Obviously you don't need this if you're using PHP 5.3 or better, or if you can install the PECL library into PHP 5.2, but if you can't do that, this is a good alternative.

like image 158
Spudley Avatar answered Oct 04 '22 12:10

Spudley


Quote:

This extension may be installed using the bundled version as of PHP 5.3.0, or as a PECL extension as of PHP 5.2.0. In other words, there are two methods to install the intl extension.

Instructions here

General installtion instructions

pecl install intl
pecl install idn

Then add the extensions in your php.ini or relevant configuration files.

like image 44
Peter Lindqvist Avatar answered Oct 04 '22 12:10

Peter Lindqvist