Search code examples
phpdnsutfidn

idn_to_ascii() in 5.2.17


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?


Solution

  • 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.