idn_to_ascii() in 5.2.17

旧巷老猫 提交于 2021-02-20 11:50:45

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/5405505/idn-to-ascii-in-5-2-17

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!