88

I've been using this exact same code for ages, and I have never had a single problem. Now all of a sudden it has stopped working.

I have read across the internet about this problem, and apparently you need PHP 5.3 or higher installed, and the PHP intl plugin installed. I have both of these, yet I am still receiving a Fatal error: Class 'NumberFormatter' not found error whenever I use the following function:

function format_item($value)
{
       $format = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
       return $format->formatCurrency($value, 'AUD');
}

Also, here is a snippit from my php.ini file showing that I have the PHP intl plugin installed:

[intl]
intl.default_locale = fr_FR
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
intl.error_level = E_WARNING

I also have the extension=php_intl.dll in my php.ini, and it is also in my directory.

Why am I getting this error?

cannatown
  • 945
  • 1
  • 6
  • 9
  • 3
    Did you uncomment the extension from php.ini? Did you restart apache after you uncommented it? I found this, look at it and see if it helps you http://stackoverflow.com/questions/1451468/intl-extension-installing-php-intl-dll – Eric Martinez May 31 '15 at 05:37
  • Yes, it is uncommented. I will take a look at that link – cannatown May 31 '15 at 05:38
  • create `phpinfo.php` and in it put: `` then navigate to the page. Confirm your version and the extension are in-fact loaded. – Wade May 31 '15 at 05:49
  • Some other useful debugging tools may be to look at your phpinfo and also looking at what extensions are actually loading with get_loaded_extensions. You can use php -i on the command line or phpinfo(). http://php.net/manual/en/function.phpinfo.php http://php.net/manual/en/function.get-loaded-extensions.php – iridian May 31 '15 at 06:01
  • PHP is definitely working. I do not have those .dll files, so I downloaded the latest version to get the .dlls and put them in my directory. The latest version of PHP doesn't even have these .dlls, so how am I supposed to get them? – cannatown May 31 '15 at 06:03
  • The currency code should be wrapped in quotes.. Should be `'AUD'`. Check the docs: http://php.net/manual/en/numberformatter.formatcurrency.php – Wade May 31 '15 at 06:04
  • @WadeShuler it is in my file, for some reason it didn't paste them in the post. I will edit it – cannatown May 31 '15 at 06:06
  • Do you have: `use NumberFormatter;` at the top of your file? If not, try removing the backslashes before `NumberFormatter` in the 2 places. Works both ways for me, no errors, but worth a shot. Other than that, I am out of ideas. If there is a newer version of PHP, upgrade to it and see. Maybe a bug with that version, or something went wrong with it. – Wade May 31 '15 at 06:08
  • Neither of those things worked. I'm going to try upgrading wamp – cannatown May 31 '15 at 06:10
  • So it happens that I already have the latest version of Wamp installed. What am I supposed to do now? – cannatown May 31 '15 at 06:33

22 Answers22

76

All you need is:

apt-get install php7.0-intl

No need to change php.ini or do anything else. (Tested on PHP 7 on Ubuntu 16.04).

The most up-voted answer here has you uncommenting a .dll which will never solve anything unless you are on a Windows server!

Nick
  • 10,904
  • 10
  • 49
  • 78
  • Yes I too encountered it few days ago and somewhere else saw `brew install php7.0-intl` for Mac and just tried `apt-get install php7.0-intl` and viola! – mascot6699 Mar 22 '17 at 10:05
  • Thanks, I encountered an issue almost similar to this but since I was using php7.3 `sudo apt-get install php7.3-intl` worked for me – Swaleh Matongwa Nov 30 '21 at 22:45
66

You just need to enable this extension in php.ini by uncommenting this line:

extension=ext/php_intl.dll

For more details visit, Enable intl extension

baikho
  • 5,203
  • 4
  • 40
  • 47
Chandz
  • 1,173
  • 3
  • 18
  • 34
28

This worked for me (Ubuntu 18.10, PHP 7.2.15)

sudo apt-get install php-intl
service apache2 restart
Wonko the Sane
  • 754
  • 3
  • 14
  • 31
13

I am using PHP 5.5 version and got the same error in Ubuntu Machine. I have installed php5-Intl package and restarted my apache server. This resolved the issue.

For PHP5

sudo apt-get install php5-intl

For PHP7

sudo apt-get install php7.0-intl

For Mac OS X, use the following command for PHP5.6

brew install php56-intl

For different OS, checkout this page : http://php.net/manual/en/intl.installation.php

To check successful installation, run the command php -m. This should show the intl package in the list.

If you are using XAMPP in Mac OS X, php-intl will sometimes create different problems. You can follow the debug steps mentioned here

If you are facing Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/intl.so' error, follow the steps as mentioned here

keya
  • 2,068
  • 2
  • 18
  • 18
10

This means that your intl package for PHP is not installed and/or not enabled.

Step 1

Make sure that you install php7.2-intl (or check that it is installed). In my case, I had PHP 7.2, but the version could change.

To install, I used

sudo apt install php7.2-intl

Step 2

After a successful installation, go to php.ini and enable that extension by removing the comment, as follows

extension=intl

Step 3

Retstart apache

sudo service apache2 restart
Greeso
  • 7,544
  • 9
  • 51
  • 77
  • i just opened php.ini in xampp server and enable extension=intl and its working great thanks a lot – softya Jun 13 '20 at 14:48
9

I am running on ubuntu-16.04 and I am using php7, I had the same issue, It is because of the php_intl extension

the way I fixed it-

  • First check the extension is installed or not on your server, use below command to check it

    php -m | grep intl
    
  • If there's no results, you must need to install it

  • If not installed, let's install it

    sudo apt-get update
    sudo apt-get install php-intl
    
  • Finally you need to restart your web server after you install

Class 'NumberFormatter' not found error in simple PHP program

https://www.howtoinstall.co/en/ubuntu/xenial/php-intl

mizan3008
  • 369
  • 3
  • 17
8

for additional, if someone come here and on Laravel using php artisan serve and facing this problem, and already uncomment

extension=intl

on php.ini, don't forget to restart your Laravel dev server.

Rio A.P
  • 1,313
  • 13
  • 20
  • 1
    This was my issue thanks! I'm using valet-linux on a new WSL2 setup and had to `valet restart` – Nate S Jan 31 '21 at 23:38
5

If you are using Google App Engine, just add:

extension = "intl.so"

to your application's php.ini file.

https://cloud.google.com/appengine/docs/php/runtime

Ben Shoval
  • 1,732
  • 1
  • 15
  • 20
5

Actually if you're using xampp and php > 7.*

edit the line ;extension=intl to extension=intl, restart mysql service and you're good to go.

Erick
  • 301
  • 4
  • 4
3

outdated

On Max OS X with PHP installed with the Homebrew, we can:

We can check is module intl installed:

$ php -m

We can check module info:

$ brew info php72-intl

And install it with:

$ brew install php72-intl
Vladimir Vukanac
  • 944
  • 16
  • 29
2

I got the same error from inside docker image php:7.4-fpm, so I added the following lines to the Dockerfile

RUN apt-get install -y libicu-dev # required dependency

RUN docker-php-ext install intl
Hany Sakr
  • 2,591
  • 28
  • 27
1

Add your PHP directory in the Path environment variable. (C:\Program Files\wamp\bin\php\phpX.XXX.XXX for wamp)

It has worked for me!

quent
  • 1,936
  • 1
  • 23
  • 28
1

(Ubuntu 20.04.3 LTS, PHP Version 7.4.30)

sudo apt-get install php7.4-intl
sudo service nginx restart
Sanaulla
  • 1,329
  • 14
  • 13
0

This seems to be some really weird problem, and I somehow fixed it by doing the following:

I upgraded my PHP in Wamp through this tutorial. I also updated my timezone in php.ini When I upgraded it didn't work, so I reverted back to my previous version of PHP, and voilà - it worked.

I have absolutely no idea how this solved the problem, however it worked for me.

Marty
  • 39,033
  • 19
  • 93
  • 162
cannatown
  • 945
  • 1
  • 6
  • 9
0

Change in php extensions did not work for me so I updated my php version from php 5.6.25 to 7.0.10 and it worked

saad
  • 1,354
  • 1
  • 14
  • 21
0

Solutions For ALL Windows and Mac.

Most of time this extension is not there, You just need to enable this extension in php.ini by uncommenting this line,

          extension=intl

if that line doesn't exists then add that line as like below in any place below first line,

         extension=intl
         extension=ext/php_intl.dll

for better result add below as like as well because with above one is in some scenario not working with only below one,

         extension=php_intl.dll

Then it look like this,

         extension=ext/php_intl.dll
         extension=php_intl.dll
         extension=intl

After That Mostly Don't Forgot to restart your server in my case I am using xampp otherwise the changes not working properly.

munazzil
  • 109
  • 2
  • 9
0

On CentOS 8:

sudo dnf install php-intl
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

the same problem happened to me, I already configured the php.ini and enabled the intl extension, the error persisted and I solved it by adding PHP in the environment variables of the system PATH in Windows

0

First of all, stop the XAMPP/Wamp and then kindly remove the starting semicolon ( ; ) from your xampp\php\php.ini the following code.

;extension=intl

And then restart your XAMPP/Wamp.

NOTE: For Windows, you can find the file in the C:\xampp\php\php.ini-Folder (Windows) or in the etc-Folder (within the xampp-Folder).

Very Important Note: "Close your Command Prompt And Restart Again" (It's very important because if you didn't restart your command prompt then changes will not be reflected.)

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
0

in case of using heroku/php you should add this to composer.json:

    "require": {
        ...
        "ext-intl": "*"
    }
Reza Babaei
  • 905
  • 1
  • 14
  • 22
0

For those ones here using docker and looking for a solution, I just added this line to my Dockerfile:

RUN apk add --no-cache icu-dev && docker-php-ext-install intl

I'm getting the image from php:8.0.20RC1-fpm-alpine3.16

Hope this help somebody

Martín Mori
  • 1,021
  • 1
  • 7
  • 5
-2

i could just do the following and it will work perfect.

$numbers = 123456789;

$toThousands = number_format($numbers);

results will be: 123,456,789, the func "number_format" is already build in function.

Codedreamer
  • 1,552
  • 15
  • 13