6

I have a simple PHP program but I am encountering this error:

Class 'NumberFormatter' not found

I have researched similar issues in Stackoverflow but honestly none gave a concrete solution. Others suggest to upgrade the version of PHP, others un-comment a specific line in the php.ini file and none of those worked for me.

Below is my code: I even used the suggested solution from https://bugs.php.net but it still doesn't work.

<!DOCTYPE html>
<html>
<body>

<?php
function writeMsg(){

$f = new \NumberFormatter("en", \NumberFormatter::SPELLOUT);    

echo $f->format(1432);
}
writeMsg();
?>  

</body>
</html>
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
TwoThumbSticks
  • 1,086
  • 3
  • 23
  • 38
  • 2
    what version of php are you using? did you [enable/install the international extension](http://stackoverflow.com/questions/15003199/php-5-3-seems-to-be-missing-intl-extension-by-default)? – devlin carnate Nov 23 '15 at 17:10

3 Answers3

16

Two things

  1. You need PHP 5.3 or above.

  2. You may not have the php-intl extension installed.

To check, run in your terminal:

php -m | grep intl

If there's no results, you'll need to install it which varies depending on your system and PHP Version

On a Mac for example, you can install it for PHP 5.6 by running:

brew install php56-intl

Make sure you restart your web server after you install!

EDIT for XAMPP:

If you're running XAMPP, then this is probably installed but not enabled.

  1. Find your php.ini file -- path-to-your-xampp/php/php.ini -- and open it in an editor.

  2. Search for php_intl. If you find ;extension=php_intl.dll, then just remove the semi-colon from the front of the line -- this uncomments it.

  3. Restart XAMPP!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
djt
  • 7,297
  • 11
  • 55
  • 102
  • I am a php newbie and just using xampp 3.2.1 PHP version is 5.5.27 HOw can I chack the extension not using the terminal? – TwoThumbSticks Nov 23 '15 at 17:17
  • In that case, it may be installed but not enabled. You'll want to find your php.ini file. Thats probably in your XAMPP application direction/php/php.ini. Open that file in an editor and search for `php_intl`. If you find `;extension=php_intl.dll`, then just remove the semi-colon from the front of the line -- this uncomments it. Then restart XAMPP – djt Nov 23 '15 at 17:21
  • Thank you solved my problem will accept the answer but I have a request. Please edit your answer to include the xampp approach to help others because there are similar questions here in stackoverflow but the accepted answers are not the correct ones. – TwoThumbSticks Nov 23 '15 at 17:38
  • @TwoThumbSticks glad it worked. I updated my answer – djt Nov 23 '15 at 17:41
1

As stated, you should have PHP 5 >= 5.3.0 version and if you already uncomment ;extension=php_intl.dll from php.ini file and still not working.. try to take a look at this answer. it really solve my problem.

intl extension php_intl.dll with wamp

curiosity
  • 834
  • 8
  • 20
1

You need to use

use \NumberFormatter;

The above code

Nazmul Haque
  • 720
  • 8
  • 13