Home >Backend Development >PHP Problem >php intl extension installation

php intl extension installation

王林
王林Original
2023-05-06 15:25:071711browse

PHP intl extension installation

PHP intl is an official extension for internationalization and localization processing, including character encoding conversion, date and time formatting, currency formatting, text sorting, and language resource processing, etc. . This extension is essential when working with multilingual websites or applications.

This article will introduce how to install and enable the PHP intl extension, and provide installation steps for multiple operating systems (Windows, Mac and Linux) for readers' reference.

Installation prerequisites

Before installing the PHP intl extension, make sure your PHP version meets the following requirements:

  • PHP 5.3.0 or higher (PHP 7 Recommended)
  • ICU library 4.0 or higher

Install the ICU library

In most cases, the ICU library is already installed on the server by default. However, you can use the following command to check whether the ICU library has been installed:

icu-config --version

If the following error message is returned:

-bash: icu-config: command not found

Then you also need to install the ICU library. Here's how to install the ICU library on each operating system:

Installing the ICU library on Mac

On Mac, you can install the ICU library through Homebrew. Open the terminal and enter the following command:

brew install icu4c

After the installation is completed, you can check the version number through the following command:

icu-config --version

Install ICU library on Linux

Install ICU on Linux Libraries require the use of a package manager. For example, on Ubuntu, you can use the following command to install:

sudo apt-get install libicu-dev

On CentOS or RedHat, you can use the following command to install:

sudo yum install libicu-devel

Install the ICU library on Windows

In On Windows, you can download the ICU-for-Windows installation program from the ICU official website https://ssl.icu-project.org/download/. Please be careful to select the correct version (x86 or x64) when installing.

Install PHP intl extension

After installing the ICU library, next we need to install the PHP intl extension. The following is how to install it on each operating system:

Installing the PHP intl extension on Mac

To install the PHP intl extension on Mac you need to use the following command:

brew install php-intl

Installation completed After that, you need to restart the Apache or Nginx server:

sudo apachectl restart

or

sudo nginx -s reload

Installing the PHP intl extension on Linux

To install the PHP intl extension on Linux, you need to use the following command:

sudo apt-get install php-intl

or

sudo yum install php-intl

After installation, you need to restart the Apache or Nginx server:

sudo service httpd restart

or

sudo service nginx reload

Install PHP intl extension on Windows

To install the PHP intl extension on Windows, you need to edit the PHP php.ini file and add the following statement in the [PHP] section:

extension=php_intl.dll

After saving, you need to restart the Apache or Nginx server.

Test

After the installation is completed, you can test whether the PHP intl extension is successful by using the following code:

$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$num = $fmt->parse( '1.234.567,89' );
echo $num;

If the normal output 1234567.89 means the extension is installed successfully .

Conclusion

The installation process for the PHP intl extension is relatively simple, but slightly different in different operating systems. This article describes the steps to install the PHP intl extension on Windows, Mac and Linux. I hope it will be helpful to readers.

The above is the detailed content of php intl extension installation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn