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 tha开发者_StackOverflow社区t. How do I encode Unicode domain names to ascii then?
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.
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.
Alternatively, you can install it using apt-get:
sudo apt-get install php7.x-intl
You need to replace 'x' by the actual php version you currently have installed.
精彩评论